Vscode: ts errors in js files

Created on 13 Jul 2020  路  20Comments  路  Source: microsoft/vscode




  • VSCode Version: latest
  • OS Version: latest Sierra

This doesn't happen when I disable the built-in TypeScript and JavaScript Language Features extension.. but then I lose a bunch of functionality....

Steps to Reproduce:

  1. Create new file named test.js add the following to it:
const submitEl = document.getElementById('submit');

submitEl.onclick = (event) => {
  console.log('submit');

  function KeyPress(e) {
    console.log('keypress', e)
  }

  document.onkeydown = KeyPress;
}
  1. Why am I getting ts errors on js files?

Screen Shot 2020-07-12 at 6 31 41 PM


Does this issue occur when all extensions are disabled?: Yes/No

Most helpful comment

Ok, glad you found the issue. Please make sure to also file an issue against the deno extension as well so they can address this

All 20 comments

Found a solution for this

After searching for what felt like an eternity, I finally found a Stack Overflow answer that resolved this for me.

The issue is "typescript.tsdk": [bad_value] is set to a bad value.

My typescript.tsdk was set to: "typescript.tsdk": "",. You want to set this to a path which contains a tsserver.js file. The path in use below is on OSX and it points to the global TypeScript npm install.

  • Open settings.json
  • Set (or add) the following property:
{
  ...
  "typescript.tsdk": "/Users/<your_username>/.npm-global/lib/node_modules/typescript/lib/",
  ...
}

Hopefully this helps someone.

Just kidding.... this is still an issue.. I have no idea what fixed it before but this stopped working the next day.. I've just being doing // @ts-nocheck at the top of all of my .js files... This never used to happen - why is it happening now??

Have you set javascript.implicitProjectConfig.checkJs: true in VS Code or does your project have a jsconfig or tsconfig that sets checkJs: true?

@mjbvz I have not set that on purpose. Let me check and see if that's set, or if anything is changing it to true. Thanks for the tip!

As soon as I upgraded to 1.47 all my purely JS projects started to show TS errors. I don't have TS on my system, nor jsconfig or tsconfig, yet even trivial code produces errors. Before 1.47 it was totally usable for JS/ES projects.

Example of an error to illustrate what I am talking about:

const identity = x => x;

In this example x is highlighted with a red squiggly line showing this error:

(parameter) x: any
Parameter 'x' implicitly has an 'any' type.ts (7006)
Peek Problem (鈱8) No quick fixes available

Why is it an error? I don't want to fix it.

Obviously, if I try to add a type annotation, it errors showing:

Type annotations can only be used in TypeScript files.ts (8010)
Peek Problem (鈱8) No quick fixes available

Which is totally fair. At least we know that it understands that this file is not TS.

Why it is bad and makes my life hell:

  • In the minimap it shows bright red on every line preventing overviewing searches and so on.
  • In the file view (Explorer) all open files are red. I use colors for modified and newly added files. Now I don't know the git status until I close files.
  • I don't like seeing errors where there are no errors. :-)

This is my settings.json just to see that it doesn't have any funny business:


Click me to expand:

{

    "gitlens.advanced.messages": {
        "suppressShowKeyBindingsNotice": true
    },
    "editor.fontLigatures": true,
    "editor.fontFamily": "Fira Code",
    "sync.gist": "0aadafae52deaff8d740ba461b9349c9",
    "sync.quietSync": false,
    "sync.removeExtensions": true,
    "sync.syncExtensions": true,
    "sync.autoDownload": false,
    "sync.autoUpload": false,
    "sync.forceDownload": false,
    "window.zoomLevel": 1,
    "breadcrumbs.enabled": true,
    "cSpell.enabledLanguageIds": [
        "asciidoc",
        "c",
        "cpp",
        "csharp",
        "css",
        "go",
        "handlebars",
        "html",
        "jade",
        "javascript",
        "javascriptreact",
        "json",
        "latex",
        "less",
        "markdown",
        "php",
        "plaintext",
        "pub",
        "python",
        "restructuredtext",
        "rust",
        "scss",
        "shellscript",
        "text",
        "typescript",
        "typescriptreact",
        "yml"
    ],
    "[javascript]": {
        "editor.defaultFormatter": "esbenp.prettier-vscode"
    },
    "[json]": {
        "editor.defaultFormatter": "esbenp.prettier-vscode"
    },
    "editor.largeFileOptimizations": false,
    "[jsonc]": {
        "editor.defaultFormatter": "esbenp.prettier-vscode"
    },
    "git.autofetch": true,
    "todo-tree.tree.showScanModeButton": false,
    "javascript.suggest.autoImports": false,
    "typescript.suggest.autoImports": false,
    "[html]": {
        "editor.defaultFormatter": "esbenp.prettier-vscode"
    },
    "search.searchEditor.reusePriorSearchConfiguration": true,
    "search.actionsPosition": "right",
    "editor.minimap.enabled": true
}

There is a project-specific setting.json:


Click me to expand:

{
    "deno.enable": false
}

Please tell me how I can help you guys to fix this problem.

@elazutkin-dynata Do see this when you disable all extensions?

Yep. Just to clarify: I used Disable All Installed Extensions command in the Command Palette. Let me know if you had something else in mind.

Ok. This is a distinct problem from @oze4's.

The error you are seeing is a suggestion. That's why it's underlined with ... instead of with a red squiggle like an error would have been. We show this suggestion in JS files because without a type annotation here, we cannot provide good IntelliSense. To disable suggestions, set "javascript.suggestionActions.enabled": false

Also, you'd need to use jsdocs to add the type annotation since this is a JS file

To disable suggestions, set "javascript.suggestionActions.enabled": false

Done. No change. Restarted. No change. What else do you have? Keep suggestions coming. :-)

Also, you'd need to use jsdocs to add the type annotation since this is a JS file

The whole point is I don't want type annotations nor jsdocs. If I wanted that, instead of dynamic languages I would use Java. Please don't ask me to change the language or update humongous projects I am charged to support.

Please share a screenshot of your editor when this problem happens, including the problems view

Here you go:

Screen Shot 2020-07-16 at 5 26 58 PM

BTW, it is with "javascript.suggestionActions.enabled": false

When you disabled extensions, did you also restart VS Code? Some extension, specifically ones like deno, require a restart to take effect. Make sure this happens when no extensions are enabled

When you disabled extensions, did you also restart VS Code?

Yes.

See my post above: https://github.com/microsoft/vscode/issues/102320#issuecomment-659706777

I take it back. I disabled all extensions, and restarted — the squiggly lines are gone. Must be an extension.

Deno extension is installed but disabled in project settings.

I enabled all extensions and disabled Deno — the problem is gone. It looks like Deno's extension is not ready.

Sorry for polluting the ticket with a different problem and thank you for helping to debug it!

Ok, glad you found the issue. Please make sure to also file an issue against the deno extension as well so they can address this

@elazutkin-dynata I recently installed the Deno extension as well. I'm on mobile right now but I will check if disabling it fixes this for me.

Nice find!

@elazutkin-dynata @mjbvz I can confirm that disabling the Deno extension resolves this issue.

Apologies for wasting your time!

Was this page helpful?
0 / 5 - 0 ratings