我收到了警告…

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

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

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

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

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


当前回答

您可以使用此代码运行

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

其他回答

我通过从tsconfig中删除"baseUrl": ""来纠正这个警告。json文件

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

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

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

为了清晰和愚蠢。

1) 打开 .vscode/settings.json。

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

3)保存。

4)重启Visual Studio代码。

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

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

当您选择“src”文件夹作为工作区文件夹时,也会发生此错误。

当选择“src”,“node_modules”所在的根文件夹时,错误消失