最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to enable ts-check in es6 - Stack Overflow

programmeradmin4浏览0评论

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?

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?

Share edited Apr 21, 2020 at 18:20 norbitrial 15.2k10 gold badges39 silver badges64 bronze badges asked Nov 5, 2018 at 15:30 user4229770user4229770 1
  • 1 I believe that errors e from typescript piler and not from eslint. To enable type checking in all js files add tsconfig.json file (if you don't have one) with checkJs piler option enabled – Aleksey L. Commented Nov 5, 2018 at 15:53
Add a ment  | 

1 Answer 1

Reset to default 4

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

{
    "pilerOptions": {
        "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 mand in scripts section:

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

发布评论

评论列表(0)

  1. 暂无评论