我收到了警告…

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

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

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

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

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


当前回答

我也有同样的问题。通过其他类导入带有“decorator warning”的类来修复。

其他回答

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

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

VSCode -> File -> Preferences -> Workspace Settings

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

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

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

在项目中创建文件tsconfig。Json,然后添加这些行

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

您可以使用此代码运行

 tsc .\src\index.ts --experimentalDecorators "true" --emitDecoratorMetadata "true"

File -> Preferences -> Settings

如果您打开存在于项目外部的TS文件,您可能会遇到这个问题。例如,我正在使用lerna,并从另一个包中打开了一个文件。尽管另一个包有自己的tsconfig和实验性的装饰器,但VsCode并不尊重它。