Removing [ts] errors from JS files In VS Code

后端 未结 8 1055
有刺的猬
有刺的猬 2021-01-31 14:44

I get these TypeScript errors VS Code while I\'m working in JS files. Is there anything I can do to disable this? I have put this in my settings and did not solve the issue:

相关标签:
8条回答
  • 2021-01-31 15:22

    Make sure javascript.implicitProjectConfig.checkJs is false VSCode settings.

    0 讨论(0)
  • 2021-01-31 15:23

    This worked for me too: File > Preferences > Settings > Extensions->TypeScript-> Javascript>Validate make sure Enable/disable JavaScript validation. is not checked

    https://stackoverflow.com/a/53745887/14728249 Thank you @BenE :)

    0 讨论(0)
  • 2021-01-31 15:29

    There's a GitHub issue that discusses the [ts] token from the errors in a bit more detail. The most relevant comment to this discussion is:

    Yes. The TypeScript extension powers our javascript intellisense which is why you see [TS] in your js file. That only indicates what extension is providing that error.

    You can disable this validation itself by adding the following to an appropriate settings.json file:

    "javascript.validate.enable": false
    

    The docs discusses this option a little bit further:

    With javascript.validate.enable: false, you disable all built-in syntax checking. If you do this, we recommend that you use a linter like ESLint to validate your source code.

    As noted above, this disables all built-in syntax checking. Although the suggestion is to use something like ESLint instead, there might be another option if you're specifically concerned about the import/export errors. You can add a jsconfig.json file to your project with the following content:

    {
        "compilerOptions": {
            "module": "es2015"
        }
    }
    

    This instructs VS Code to use the es2015 module syntax (import/export), which appears to make it happier.

    0 讨论(0)
  • 2021-01-31 15:33

    On Windows- File > Preferences > Settings Go to Extensions->TypeScript-> Javascript>Validate make sure Enable/disable JavaScript validation. is not checked

    0 讨论(0)
  • 2021-01-31 15:35

    I don't have enough information about project setup and code, but it looks like you are trying to load .js files as typescript.

    To use JavaScript files in Typescript projects you must enable allowJs flag, either in command line --allowJs or in the tsconfig.json as "allowJs": true.

    But, if the .js files should not be part of the TS project but just are in the same directory tree, you need to review your exclude and include properties of tsconfig.json

    0 讨论(0)
  • 2021-01-31 15:39

    This works for me

    On Windows- File > Preferences > Settings

    make sure validate is not enable

    0 讨论(0)
提交回复
热议问题