TypeScript 错误 TS5023:未知的编译器选项“严格”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43815501/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 04:31:17  来源:igfitidea点击:

TypeScript error TS5023: Unknown compiler option 'strict'

typescript

提问by benjaminz

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

tsconfig.json文件中使用选项“strict”时,出现错误:

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

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

And also my Visual Studio Code editor.

还有我的 Visual Studio Code 编辑器。

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

有谁知道我做错了什么?这是我的 tsconfig.json 文件:

{
  "compilerOptions": {
    "strict": true,
    "sourceMap":  true
  }
}

回答by Aluan Haddad

You need the latest version.

您需要最新版本。

Specifically, you need TypeScript@>=2.3

具体来说,你需要 TypeScript@>=2.3

For project level installation (recommended)

用于项目级安装(推荐)

npm install --dev typescript@latest

If you use tscvia the global command line

如果您tsc通过全局命令行使用

npm install --global typescript@latest

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

覆盖 VS Code 使用的版本以使用全局安装

  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"
    
  1. 打开用户设置

  2. 改成如下(把我的名字换成你的)

    // Place your settings in this file to overwrite the default settings
    {
      "typescript.tsdk": "C:/Users/Aluan/AppData/Roaming/npm/node_modules/typescript/lib",
       //..
    
  3. 如果您运行的是 Linux 或 OSX,路径将类似于

    "~/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...

也就是说,最新的 VS Code 应该随 TypesScript@>3 一起提供,所以除了更新它之外你不需要做任何事情......

Other package managers:

其他包管理器:

JSPM:

JSPM:

command line:

命令行:

jspm install --dev typescript@latest

VS Code project level settings:

VS Code 项目级别设置:

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

Yarn:

纱:

command line:

命令行:

yarn add --dev typescript@latest

VS Code project level settings:

VS Code 项目级别设置:

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

回答by andras

I had this same error.

我有同样的错误。

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

什么固定对我来说是卸载全球tslint,并确保我有最新的tslinttsctypescript安装。(看起来并非所有组合都有效。)

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

在本地安装这些并删除所有全局包后,我终于收到了我的编译错误。