【问题标题】:Visual Studio Code 'experimentalDecorators' Issue for Angular BuildAngular 构建的 Visual Studio Code 'experimentalDecorators' 问题
【发布时间】:2017-10-03 03:36:42
【问题描述】:

我在使用 VSC 时遇到问题,我的所有打字稿类都在触发智能感知并出现以下警告:

"[ts] 实验性支持是一项可能会更改的功能 在未来的构建中。将“experimentalDecorators”选项设置为删除 这个警告。”

这是一个记录在案的问题,这些帖子中记录了各种修复:

但是我使用的是现在更新版本的 VSC(实际上是我今天更新它似乎触发了某些事情),因此这里提到的解决方案似乎都不起作用。

我有:

  • 在我的 .vscode 设置中添加了 "typescript.tsdk": "../node_modules/typescript/lib" 选项
  • 删除了应用程序根目录中 tsconfig.json 文件中的多行,包括 lib、baseUrl 等,在两次尝试之间完全重新打开 VSC
  • 在我的 package.json 中尝试了备用 Typescript 版本
  • 偶然重新启动了我的计算机

这是我当前的 tsconfig.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "baseUrl": "src",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2016",
      "dom"
    ]
  }
}

我使用的是 VSC 版本 2.3.2,我的 package.json 中的 TS 版本设置为“typescript”:“~2.2.0”。

这里有什么我遗漏的吗?

【问题讨论】:

  • 版本不匹配不应导致此错误,但您肯定应该更新到最新的打字稿。
  • 既然你使用outDir,你也应该使用rootDir或者排除你的dist目录
  • @AluanHaddad 我已通过 npm 更新到最新的 typescript 版本,添加了 rootDir(值为 src)并尝试使用 ./dist/out-tsc 目录删除 outDir,这些都没有奏效。你说的排除是这个意思吗?
  • @jmcgrory,你解决了这个问题吗?
  • @vlio20 不,但我建议尝试我链接的其他解决方案,因为它们适用于其他人。我正在等待另一个 VSC 更新,看看是否会动摇事情。在那之前我会忽略这个问题。

标签: javascript angular typescript visual-studio-code


【解决方案1】:
this is what what worked for me:  
tsconfig.js (relevant part):
{
  "compilerOptions": {
    ...
    "declaration": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "outDir": "dist",
    ...
  },
  "include": [
    "src/index.ts"
  ]
}

这是完整的文件:

{
  "compilerOptions": {
    "declaration": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "allowJs": true,
    "lib": [
      "es6"
    ],
    "module": "commonjs",
    "moduleResolution": "node",
    "outDir": "dist",
    "sourceMap": true,
    "target": "es6"
  },
  "include": [
    "src/db/**/*.ts",
    "src/index.ts"
  ]
}

基本上我只是添加了 include 属性而不是使用 files 属性。

【讨论】:

  • 很遗憾,这没有奏效,您能发布完整的 tsconfig.js 吗?
  • 谢谢!仍然没有运气,但这并没有阻止我的工作,所以也许我会在今年年底之前解决这个问题:D
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-30
  • 2022-01-07
  • 1970-01-01
  • 2022-01-24
  • 1970-01-01
  • 2013-03-18
相关资源
最近更新 更多