How to enable ts-check in es6

巧了我就是萌 提交于 2021-02-19 04:55:07

问题


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:


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"



来源:https://stackoverflow.com/questions/53157373/how-to-enable-ts-check-in-es6

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!