stefan2410
stefan2410

Reputation: 2051

How to disable TypeScript warnings in VSCode?

I don't use TypeScript for the time being. Only ES6 with babel.
I don't have installed TypeScript in node_modules.

I get a specific warning from VSCode every time I open a workspace.

\node_modules\typescript\lib doesn't point to a valid tsserver install. Falling back to bundled TypeScript version.

How can I get rid of such warnings? Or should I change editor in order to feel calm?

Upvotes: 113

Views: 117158

Answers (8)

Kostas Panagiotakis
Kostas Panagiotakis

Reputation: 41

To solve this issue I am using a hybrid approach.

I have disabled typescript validation throught the settings.json file

typescript.validate.enable": false

and I left javascript validation enabled

javascript.validate.enable": true

While working on a project and get any unresonable errors due to typescript enforcement, I just use the @ts-ignore flag above the line in error and everything is as expected.

With this approach, quick fix and import / export options are enabled, keeping vscode happy.

Upvotes: 0

ruffin
ruffin

Reputation: 17453

Good answers, but I had a situation where I only wanted to turn off TypeScript validation for some unported vanilla JavaScript that we're using in TypeScript land. Our use of eslint didn't catch nearly as many errors as the TypeScript validator, so to preserve the ability to validate "real" *.ts, it was important to only turn off TypeScript validation for specific files.

Easy enough, it turns out. From bobbyhadz.com:

Use the // @ts-nocheck comment to disable type checking for an entire file in TypeScript.

...

// @ts-nocheck

console.log('no errors' / 0);
console.log('no errors' / 0);

And from the TypeScript docs (which shows ways to get even more granular):

You can skip checking some files by adding a // @ts-nocheck comment to files.

TypeScript may offer you errors which you disagree with, in those cases you can ignore errors on specific lines by adding // @ts-ignore or // @ts-expect-error on the preceding line.

// @ts-check
/** @type {number} */
var x;
 
x = 0; // OK
// @ts-expect-error
x = false; // Not OK

Upvotes: 6

Johannes Rieken
Johannes Rieken

Reputation: 3611

TypeScript and JavaScript validation can be turned off in VS Code with these two settings:

"typescript.validate.enable": false,
"javascript.validate.enable": false,

Upvotes: 208

Guus
Guus

Reputation: 81

In my case it was caused because there was extension that used vscode.typescript-language-features extension.

I still wanted javascript errors to be shown so "javascript.validate.enable": false, wasn't an option.

By disabling the extension "VueDX" that was using the @builtin extension it fixed the issue and still shows javascript syntax errors.

You can search all the typescript extensions by searching on @builtin typescript

Upvotes: 8

Andrew
Andrew

Reputation: 1

As per here, you can disable built-in extensions in VSCode now. In the Extensions tab on the left (Ctrl+Shift+X), search for @builtin + JavaScript / TypeScript. Then click the little gear icon next to an Extension and click Disable.

I disabled TypeScript and JavaScript Language Features (there is a JavaScript Language Basics Extension) and TypeScript Language Basics.

Upvotes: 15

marcdahan
marcdahan

Reputation: 3042

  1. open the command palette : CTRL + SHIFT + P

  2. open the file settings.json :

enter image description here

  1. add these 2 lines of code:

    "typescript.validate.enable": false,
    "javascript.validate.enable": false,
    

Upvotes: 47

K F
K F

Reputation: 1546

If you want to modify a setting, open the settings option (there is a new settings editor by the time I am writing this) and search for the setting you want to modify. I was attempting to change the typescript validation, but I wasn't allowed as the document was read only. If you hover over the setting, you get a pen on the left of the setting. If you right click on the pen, it will give you the option of true or false, as for my case I was targeting "typescript.validate.enable". I changed it to false, which in turn, VS code copied the code into the right of the screen with the new value. In short, the left is the settings.json file. On the right, you have the user-settings.json. You are only allowed to modify the user settings and the user setting can override any settings in the main settings.json file. -Kf

enter image description here

Upvotes: 2

Bernard Leech
Bernard Leech

Reputation: 764

I was having a similar problem. I had an incorrect setting for typescript.tsdk in my user settings:

"typescript.tsdk": null

To fix it, you can either set the location to a valid location:

"typescript.tsdk": "/usr/local/lib/node_modules/typescript/lib",

or just remove the line from your settings if are not using Typescript.

If you need more detail, I found the VSCode docs to be very concise and easy to understand.

Upvotes: 14

Related Questions