The type checking is opt-in. You can apply it to an individual file, per project, or everywhere.
If you want to try it out for a file, just add the comment
// @ts-check to the top of a file. For example, the code below tries to multiply a number with a string.
let x = "blah";
let y = x * 2;
You will see red underlining under the offense to point out the error, and you will see the error in the problems tab.
JS/TS › Implicit Project Config: Check JS setting.
Alternatively, you can place a
"exclude": ["node_modules", "**/node_modules/*"]
The advantage of using
jsconfig.json is that you can target the files you want checked through
You can use
// @ts-nocheck to disable type checking inside a file if you want to make an exception also.
JSDoc annotations are used to describe your code and generate documentation. Part of that specification is to add types to variables, through this we get can extra type checking in VS Code.
JSDoc annotations come before a declaration in a comment block. In the example below, I specify a type for the parameter and the return value.
You can see it catches a mistake when I provide a number as argument for the function call
You can find the full list of supported JSDoc patterns in: TypeScript Reference - JSDoc Supported Types.