我收到了警告…

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

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

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

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

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


当前回答

如果你在Visual studio工作。您可以尝试此修复

卸载你的项目从visual studio 转到项目主目录,打开“csproj”文件。 将TypeScriptExperimentalDecorators添加到此部分,如图所示 在Visual studio中重新加载项目。

在这个位置查看更多细节。

其他回答

您也可以尝试使用ng build。我刚刚重建了应用程序,现在它不遵守。

如果你使用Deno JavaScript和TypeScript运行时,并且在tsconfig中启用了experimentalDecorators:true。json或VSCode ide设置。这是行不通的。根据Deno要求,在运行Deno文件时需要提供tsconfig作为标志。参见自定义TypeScript编译器选项

在我的特殊情况下,我正在运行一个Deno测试并使用。

$ deno test -c tsconfig.json

如果它是一个文件,你会有

 $ deno run -c tsconfig.json mod.ts

我tsconfig.json

{
  "compilerOptions": {
    "allowJs": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "module": "esnext"
  }
}

这个错误也可能意味着tsconfig.json中有错误 以我为例,我在图书馆周围移动,没有固定路径

"extends": "../../tsconfig.base.json",

修复后,错误立即消失,不需要重新启动VS Code。

在tsconfig中添加以下行。重新启动VS Code。

{
    "compilerOptions": {
        "experimentalDecorators": true,
        "target": "es5",
        "allowJs": true
    }
}

在我的情况下,我通过在我的tsconfig中设置“include”:["src/**/*"]来解决这个问题。Json文件和重新启动vscode。 我从一个github问题得到了这个解决方案:https://github.com/microsoft/TypeScript/issues/9335