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.
    – cartant
    May 6, 2017 at 0:49
  • Works fine in VS Code 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. 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"
}
4
  • 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
    – benjaminz
    May 8, 2017 at 13:33
  • 1
    Are you not able to update globally? npm i -g [email protected] May 8, 2017 at 17:38
  • You can also tell VS Code to use your local version. May 8, 2017 at 17:39
  • 1
    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.
    – benjaminz
    May 8, 2017 at 18:12
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
  • 1
    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. Mar 27, 2020 at 11:51
1

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

dependencies: {
  ...
  "tsc": "^1.20150623.0"
  ...
}
1
  • 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. Jul 5 at 10:50
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.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.