【问题标题】:How to make VSCode show me strictNullChecks Typescript errors如何让 VSCode 向我展示 strictNullChecks Typescript 错误
【发布时间】: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


【解决方案1】:

检查文件是否未被您的tsconfig.json 中的include 或exclude 规则排除。

可能的情况包括:

  • 不包括嵌套文件夹(例如,使用 *.ts、./*.ts 或其他变体,而不是 **/*.ts)。这似乎是原始问题中的问题。
  • 新添加的 include 规则,以前不存在 - 在此处指定任何值将覆盖默认值 **/*.*。

感谢 Matt Bierner 在问题评论中提供的提示。但是,它没有作为答案发布,因此没有适当的可见性或显着性。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-07
    • 1970-01-01
    • 1970-01-01
    • 2020-10-02
    • 2017-01-04
    • 2022-07-04
    相关资源
    最近更新 更多