如何处理Angular项目在Visual Studio Code打开报关于@Decorators的警告信息

时间:2022-07-23
本文章向大家介绍如何处理Angular项目在Visual Studio Code打开报关于@Decorators的警告信息,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

我最近用Visual Studio Code开发Angular项目时,打开app.component.ts, 就遇到如下的警告消息:

Experimental support for decorators is a feature that is subject to change in a future release. Set the ‘experimentalDecorators’ option in your ‘tsconfig’ or ‘jsconfig’ to remove this warning.ts(1219)

解决办法:

在项目根目录的tsconfig.json文件里,加入如下设置:

/*
  This is a "Solution Style" tsconfig.json file, and is used by editors and TypeScript’s language server to improve development experience.
  It is not intended to be used to perform a compilation.

  To learn more about this file see: https://angular.io/config/solution-tsconfig.
*/
{
  "files": [],
  "references": [
    {
      "path": "./tsconfig.app.json"
    },
    {
      "path": "./tsconfig.spec.json"
    }
  ],
  "compilerOptions": {
    "experimentalDecorators":true,
    "emitDecoratorMetadata": true
  }
}

关掉所有文件,进入Angular项目根目录,code .重启Visual Studio Code,错误消失: