如何在es6中启用ts-check [英] How to enable ts-check in es6
问题描述
最近,我发现Visual Code具有一个不错的功能,可以在JavaScript文件中进行类型检查.我要做的就是在文件顶部键入//@ ts-check
,对我来说是个很大的好处,所以我想在每个JavaScript文件中全局使用它,我怎么能做到而又不用每次都在一行顶部写该行呢?文件?
按照Aleksey L.的注释,我使用以下配置将其添加到根目录 tsconfig.json
中,并且有效:
{"compilerOptions":{"module":系统","noImplicitAny":否,"removeComments":是的,"preserveConstEnums":是的,"sourceMap":是的,"outDir":"./dist","rootDir":"./src","checkJs":是的,"allowJs":是的,"jsx":反应","experimentalDecorators":是的,"moduleResolution":节点"},包括": ["src/**/*"],排除": ["./node_modules","dist"]}
如果您想使用 npm脚本
进行检查,您还需要安装 typescript
并在 scripts
部分中使用此命令:/p>
"typecheck":"tsc --project tsconfig.json --noEmit"
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?
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"
这篇关于如何在es6中启用ts-check的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!