16
votes

When using the option "strict" in tsconfig.json file, I get the error:

error TS5023: Unknown compiler option 'strict'

But this compiler option is clearly allowed in the official documentation:

Reference: https://www.typescriptlang.org/docs/handbook/compiler-options.html

And also my Visual Studio Code editor.

Does anyone know what I did wrong? Here is my tsconfig.json file:

{
  "compilerOptions": {
    "strict": true,
    "sourceMap":  true
  }
}
4
According to the docs "Enabling --strict enables --noImplicitAny, --noImplicitThis, --alwaysStrict and --strictNullChecks." It sounds like it's for the command line only and you have to explicitly enable the aforementioned options in a tsconfig.json file.cartant
Works fine in VS CodeAluan Haddad
@cartant that is not true at all. The "strict" flag is fully supported in tsconfig.json, I've been using it for weeks.Aluan Haddad

4 Answers

36
votes

You need the latest version.

Specifically, you need TypeScript@>=2.3

For project level installation (recommended)

npm install --dev typescript@latest

If you use tsc via the global command line

npm install --global typescript@latest

To override the version used by VS Code to use your global installation

  1. Open user settings

  2. Change it as follows (replace my name with yours)

    // Place your settings in this file to overwrite the default settings
    {
      "typescript.tsdk": "C:/Users/Aluan/AppData/Roaming/npm/node_modules/typescript/lib",
       //..
    
  3. If you are running Linux or OSX the path will be something like

    "~/npm/node_modules/typescript/lib"
    

That said, the latest VS Code should ship with TypesScript@>3 so you shouldn't need to do anything except update it...

Other package managers:

JSPM:

command line:

jspm install --dev typescript@latest

VS Code project level settings:

{
  "typescript.tsdk": "./jspm_packages/npm/typescript@latest/lib"
}

Yarn:

command line:

yarn add --dev typescript@latest

VS Code project level settings:

{
  "typescript.tsdk": "./node_modules/typescript/lib"
}
3
votes

I had this same error.

What fixed for me was uninstalling the global tslint and making sure that I have the latest from tslint, tsc, and typescript installed. (Looks like not all combinations work.)

After installing these locally and removing all global packages, I have received finally my compilation errors.

0
votes

For me the problem was, that the folder name of the project I was debugging included characters "{" and "}". After removing curly brackets from the folder name, it started to work.

0
votes

For me I had tsc in my dependencies. After npm uninstall tsc, it worked.

dependencies: {
  ...
  "tsc": "^1.20150623.0"
  ...
}