我收到了警告…

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

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

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

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

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


当前回答

创建一个新的Angular服务时,我会在vscode中得到这个警告

@Injectable({
  providedIn: 'root'
})

语法(而不是在app.module.ts中提供服务)。

警告一直持续到我在项目的某个地方引用新服务为止。一旦该服务被使用,警告就会消失。不需要更改typescript配置或vscode设置。

其他回答

File -> Preferences -> Settings

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

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

在Visual Code Studio中 进入文件>>首选项>>设置,在搜索字段中搜索“decorator”,并检查图像中的选项。

"javascript.implicitProjectConfig.experimentalDecorators": true

将解决这个问题。

您可以使用此代码运行

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