【发布时间】:2022-04-23 05:21:26
【问题描述】:
当我使用以下tsconfig.json 构建我的项目时,由于最近添加了strictNullChecks: true 而出现错误。
{
"version": "2.3.4",
"compilerOptions": {
"allowSyntheticDefaultImports": false,
"removeComments": true,
"strictNullChecks": true,
"sourceMap": true,
"jsx": "react",
"target": "es5",
"lib": [
"es6",
"dom",
"scripthost"
],
"outDir": "../build/"
},
"include": [
"./*.ts",
"./*.tsx",
"./{client,mobile,server,shared,test,tools}/*.ts",
"./{client,mobile,server,shared,test,tools}/*.tsx",
"./{client,mobile,server,shared,test,tools}/**/*.ts",
"./{client,mobile,server,shared,test,tools}/**/*.tsx",
"./desktop/*.ts"
]
}
但是,我在 VSCode 中没有看到任何错误。
我还有以下 vscode 设置:
"typescript.tsdk": "./node_modules/typescript/lib",
在 VSCode 中似乎一切正常除了 strictNullChecks 错误。
【问题讨论】:
-
在一个 ts 文件中你期望严格的 null 错误,如果你在 vscode 中运行
typescript: Go to project configuration命令会发生什么?另外,右下角的状态栏显示的是什么打字稿版本? -
啊。有趣...“文件不是 TypeScript 项目的一部分”
-
我不知道为什么它没有找到它....
-
嗯。当我摆脱
include字段时似乎工作...... -
你所在的文件的路径是什么?你可能需要使用像
./**/*.ts这样的全局对象
标签: typescript visual-studio-code