我收到了警告…

对装饰器的实验性支持是一个在未来版本中可能会更改的特性。设置'experimentalDecorators'选项'以删除此警告。

... 即使我的编译选项在tsconfig。Json有以下设置:

"emitDecoratorMetadata": true,
"experimentalDecorators": true,

奇怪的是,一些使用装饰器的随机类不显示警告,但同一项目中的其他类会显示警告。

在TypeScript编译器中,什么会导致这种行为?


当前回答

请按照以下步骤删除此警告信息。

步骤1: 在你的IDE中找到setting,然后搜索experimentalDecorators。

步骤2:然后单击复选框,警告已在您的页面中删除。

其他回答

如果您正在使用cli编译*。在ts文件中,可以使用以下命令设置experimentalDecorators:

 tsc filename.ts --experimentalDecorators "true"

为了清晰和愚蠢。

1) 打开 .vscode/settings.json。

2)添加“typescript”。Tsdk ": "node_modules/typescript/lib"

3)保存。

4)重启Visual Studio代码。

打开设置。Json文件在以下位置<project_folder>/.vscode/settings.json

或者您可以从下面提到的菜单中打开该文件

VSCode -> File -> Preferences -> Workspace Settings

然后在“设置”中添加以下行。json文件

{
    "typescript.tsdk": "node_modules/typescript/lib",
    "enable_typescript_language_service": false
}

这是所有。关于'experimentalDecorators'你不会看到任何警告/错误

VScode开放。 按ctrl +逗号 按照屏幕截图中的说明操作 搜索有关 experimentalDecorators 编辑它

我在项目中使用了React和Nest。 后端显示此错误,但将这两行添加到react的tsconfig。Json出于某种原因修复了这个问题。此外,以上的一切都不适合我

"compilerOptions": {
    ...
    "experimentalDecorators": true,
    "strictPropertyInitialization": false
},