23

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
  }
}
3
  • 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. Commented May 6, 2017 at 0:49
  • Works fine in VS Code Commented May 6, 2017 at 0:57
  • 1
    @cartant that is not true at all. The "strict" flag is fully supported in tsconfig.json, I've been using it for weeks. Commented May 6, 2017 at 1:06

4 Answers 4

43

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...

Naturally, this doesn't require npm. The following are examples using 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"
}
Sign up to request clarification or add additional context in comments.

4 Comments

Thank you! For me the problem is I use tsc from command line, and even though I've already updated my local typescript to latest version it still throws error TS5023
Are you not able to update globally? npm i -g [email protected]
You can also tell VS Code to use your local version.
No sorry for the misunderstanding, I got it working perfectly. I was trying to say that before I updated globally it didn't work, your second command helped resolving this.
3

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.

1 Comment

Also was the fix for me. I ran npm uninstall -g typescript tslint tsc and then, in my project, npm install --save-dev typescript tslint tsc and the Unknown compiler option 'strict' was finally gone.
1

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

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

1 Comment

I didn't consider that possibility when I answered the question but you're absolutely correct that this could be the cause of the of an error which manifests the similar symptoms as that in the OP.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.