我收到了警告…
对装饰器的实验性支持是一个在未来版本中可能会更改的特性。设置'experimentalDecorators'选项'以删除此警告。
... 即使我的编译选项在tsconfig。Json有以下设置:
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
奇怪的是,一些使用装饰器的随机类不显示警告,但同一项目中的其他类会显示警告。
在TypeScript编译器中,什么会导致这种行为?
我收到了警告…
对装饰器的实验性支持是一个在未来版本中可能会更改的特性。设置'experimentalDecorators'选项'以删除此警告。
... 即使我的编译选项在tsconfig。Json有以下设置:
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
奇怪的是,一些使用装饰器的随机类不显示警告,但同一项目中的其他类会显示警告。
在TypeScript编译器中,什么会导致这种行为?
当前回答
我在下面的语句中有这个错误
对装饰器的实验性支持是一个在未来版本中可能会更改的特性。在你的tsconfig或jsconfig中设置'experimentalDecorators'选项来删除这个警告。ts(1219)
这是因为我的组件没有在AppModule或(app.module.ts)中注册 我简单地给命名空间
import {abcComponent} from '../app/abc/abc.component';
并在申报中进行了登记
其他回答
File -> Preferences -> Settings
在tsconfig中添加以下行。重新启动VS Code。
{
"compilerOptions": {
"experimentalDecorators": true,
"target": "es5",
"allowJs": true
}
}
我在Angular 2中创建可注入服务时也遇到了同样的问题。 我把所有的东西都放在tsconfig中。我仍然在ColorsImmutable行得到这个错误。
@Injectable()
export class ColorsImmutable {
修复方法是在模块级或组件级注册服务 使用providers数组。 提供者:[ColorsImmutable],
在项目中创建文件tsconfig。Json,然后添加这些行
{
"compilerOptions": {
"experimentalDecorators": true,
"allowJs": true
}
}
如果您正在使用cli编译*。在ts文件中,可以使用以下命令设置experimentalDecorators:
tsc filename.ts --experimentalDecorators "true"