How to make VSCode show me strictNullChecks Typescript errors

Viewed 2215

When I build my project with the following tsconfig.json, I get an error due to recently adding 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"
    ]
}

However, I don't see any errors in VSCode.

I also have the following vscode setting:

"typescript.tsdk": "./node_modules/typescript/lib",

Everything seems to work fine in VSCode except strictNullChecks errors.

1 Answers

Check that the file is not excluded by the include or exclude rules in your tsconfig.json.

Likely scenarios include:

  • Not including nested folders (e.g. using *.ts, ./*.ts, or other variants, instead of **/*.ts). This appears to have been the issue in the original question.
  • A newly added include rule when none was previously present - specifying any value here will override the default value of **/*.*.

Credit to Matt Bierner for tips in the comment on the question. However, it wasn't posted as an answer and so doesn't have proper visibility or prominence.

Related