user3284707
user3284707

Reputation: 3341

VS Code not showing Typescript errors inline

I am confused why my VSCode isn't showing any Typescript errors.

When I run tsc in the terminal then I do see the errors showing, but these are not in my files inline.

My current setup

tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "allowJs": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "preserve",
    "lib": [
      "es2015",
      "dom"
    ],
    "skipLibCheck": false
  },
  "include": [
    "src"
  ]
}

index.ts - Expected error thrown but not

const a: number = 'test';

enter image description here

I have also updated the settings in VS to add the following as per the advice from this link, but still not showing any errors.

https://stackoverflow.com/a/53134524/3284707

enter image description here

Upvotes: 4

Views: 3947

Answers (2)

gr3821
gr3821

Reputation: 56

For me, this issue was caused by VS Code using a different TSC version for intellisense than was installed in my project. My project's package.json specified 4.7.3, while VS Code was using 4.9.4. There was a change in 4.8.x that meant some code that didn't compile before now did (believe this was the change: Announcing TypeScript 4.8). Of course, VS Code didn't show this error because it was using a later version. So, I had the issue described by the OP where running TSC in the terminal showed errors, but VS Code didn't give me any feedback.

I strongly recommend changing VS Code's setting so that it uses the same TSC version as specified in your package.json. You can read about how to do that here: Using the workspace version of TypeScript

Moreover, and I'm not certain how this relates to VS Code and my project using different TSC versions, but after making VS Code use the same version as my project, various performance problems I had been experiencing when navigating to definition, viewing hover tooltips, and more were completely resolved. So, if you're experiencing performance issues like those, give this fix a try.

Upvotes: 4

user3284707
user3284707

Reputation: 3341

Not sure if this is really a proper solution or not, but worked for me.

I added the VSCode extension TypeScript God and then it all kicked into life.

enter image description here

Upvotes: 1

Related Questions