How to enable ts-check in es6

Viewed 2022

Recently I have found Visual Code has a nice feature for type checking in JavaScript files. All I have to do is to type on top of file // @ts-check, it is great benefit for me, so I want to use it globally on every JavaScript file, how could I could I do it without writing that line every time on top of a file?

1 Answers

As per Aleksey L. comment I added to root directory tsconfig.json with this configuration and it works:

{
    "compilerOptions": {
        "module": "system",
        "noImplicitAny": false,
        "removeComments": true,
        "preserveConstEnums": true,
        "sourceMap": true,
        "outDir": "./dist",
        "rootDir": "./src",
        "checkJs": true,
        "allowJs": true,
        "jsx": "react",
        "experimentalDecorators": true,
        "moduleResolution": "node"
    },
    "include": [
        "src/**/*"
    ],
    "exclude": [
        "./node_modules",
        "dist"
    ]
}

also if you want to check it with npm script all you need is to install typescript and use this command in scripts section:

"typecheck": "tsc --project tsconfig.json --noEmit"

Related