我收到了警告…
对装饰器的实验性支持是一个在未来版本中可能会更改的特性。设置'experimentalDecorators'选项'以删除此警告。
... 即使我的编译选项在tsconfig。Json有以下设置:
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
奇怪的是,一些使用装饰器的随机类不显示警告,但同一项目中的其他类会显示警告。
在TypeScript编译器中,什么会导致这种行为?
我收到了警告…
对装饰器的实验性支持是一个在未来版本中可能会更改的特性。设置'experimentalDecorators'选项'以删除此警告。
... 即使我的编译选项在tsconfig。Json有以下设置:
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
奇怪的是,一些使用装饰器的随机类不显示警告,但同一项目中的其他类会显示警告。
在TypeScript编译器中,什么会导致这种行为?
当前回答
我也有同样的问题。通过其他类导入带有“decorator warning”的类来修复。
其他回答
这个答案是为那些使用Javascript项目而不是Typescript项目的人准备的。而不是tsconfig。Json文件,你可以使用jsconfig。json文件。
在有decorator警告的特殊情况下,你可以在文件内部写:
{
"compilerOptions": {
"experimentalDecorators": true
}
}
对于有问题的行为,最好在配置文件中指定“include”,并重新启动编辑器。如。
{
"compilerOptions": {
"target": "ES6",
"experimentalDecorators": true
},
"include": [
"app/**/*"
],
"exclude": [
"node_modules"
]
}
打开设置。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中删除"baseUrl": ""来纠正这个警告。json文件
在tsconfig中添加以下行。重新启动VS Code。
{
"compilerOptions": {
"experimentalDecorators": true,
"target": "es5",
"allowJs": true
}
}
步骤1:在VS code中按ctrl +
步骤2:输入'js/ts。implicitProjectConfig: Experimental Decorators的搜索框
第三步:选中与搜索相关的复选框