【问题标题】:ExperimentalDecorators Warning实验装饰器警告
【发布时间】:2018-04-05 12:00:28
【问题描述】:

我有一个使用 Angular 4 的应用程序,我尝试使用 jasmine 和 Karma 进行测试。但是它发生了这个错误。

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

这是我的 tsconfig 文件

{
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/",
    "baseUrl": "./",
    "sourceMap": true,
    "declaration": true,
    "module": "commonjs",
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es6",
      "dom"
    ]
  },
  "angularCompilerOptions": {
    "genDir": "aot",
    "strictMetadataEmit": true
  }
}

我刚刚编辑了VScode的settings.json并把这段代码放了

"typescript.tsdk": "node_modules\\typescript\\lib"

但是没有用。

【问题讨论】:

    标签: angular typescript visual-studio-code karma-jasmine vscode-settings


    【解决方案1】:

    我刚刚遇到了同样的问题。我按照以下步骤解决了这个问题:

    1- 将此行添加到我的 Visual Studio Code 设置中: “javascript.implicitProjectConfig.experimentalDecorators”:是的,

    2- 将选项“experimentalDecorators”:true,添加到项目的 tsconfig.json 文件的 compilerOptions 中。 (正如您在代码中已有的那样)

    我的问题解决了。

    【讨论】:

      【解决方案2】:

      如果您在 Visual Studio Code 的项目在太窄的范围内打开时单击任何相关声明,您仍然会收到错误消息,即当 VSC 甚至不知道您的 tsconfig.json 文件存在时,因为它没有打开在您的文件夹视图中。

      【讨论】:

        【解决方案3】:

        如果您不想创建文件 jsconfig.jsontsconfig.json,您可以在 Visual Studio Code 中为您的所有项目启用 experimentarDecorators

        1. 文件 > 首选项 > 设置
        2. 搜索:experimentalDecorators
        3. 启用复选框

        【讨论】:

          猜你喜欢
          • 2017-02-08
          • 2017-05-25
          • 2018-03-31
          • 2016-11-11
          • 2015-10-22
          • 2020-11-08
          • 2021-11-01
          • 2020-11-07
          • 2018-11-19
          相关资源
          最近更新 更多