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
TypeScript error TS5023: Unknown compiler option 'strict'
提问by benjaminz
When using the option "strict" in tsconfig.json
file, 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 tsc
via 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 使用的版本以使用全局安装
Open user settings
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", //..
If you are running Linux or OSX the path will be something like
"~/npm/node_modules/typescript/lib"
打开用户设置
改成如下(把我的名字换成你的)
// Place your settings in this file to overwrite the default settings { "typescript.tsdk": "C:/Users/Aluan/AppData/Roaming/npm/node_modules/typescript/lib", //..
如果您运行的是 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 tslint
and making sure that I have the latest from tslint
, tsc
, and typescript
installed. (Looks like not all combinations work.)
什么固定对我来说是卸载全球tslint
,并确保我有最新的tslint
,tsc
和typescript
安装。(看起来并非所有组合都有效。)
After installing these locally and removing all global packages, I have received finally my compilation errors.
在本地安装这些并删除所有全局包后,我终于收到了我的编译错误。