【问题标题】:experimental support for decorators visual studio 2017对装饰器视觉工作室 2017 的实验性支持
【发布时间】:2019-01-25 04:35:44
【问题描述】:

我在 Visual Studio 2017 中使用 AngularJS 创建了一个 .Net Core 项目,但是当我尝试创建服务时,我收到一个错误,因为

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

我检查了几个链接,例如编辑 tsconfig.json 以下链接,例如 link1link2

现在我的 tsconfig.json 如下所示

    {
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "experimentalDecorators": true,
    "allowJs": true,
    "noEmit": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2017",
      "dom"
    ]
  },
  "include": [
    "app/**/*"
  ],
  "files": [], //add a "files" array (in my case empty)
  "exclude": [
    "node_modules"
  ],
  "typeAcquisition": {
    "enable": true // helps fuel better js intellisense
  }
}

但我仍然看到错误,我现在一无所知。

【问题讨论】:

  • 你关闭了VS再打开了吗?可能需要重新启动智能感知才能注意到更改。
  • 另外,angular 用于 angular 2x,angularjs 用于 angularjs 1.x。
  • 我尝试关闭和打开项目,但它又给了我同样的错误

标签: angular typescript typescript2.0 asp.net-core-2.1


【解决方案1】:

添加

<PropertyGroup>
<TypeScriptExperimentalDecorators>true</TypeScriptExperimentalDecorators></PropertyGroup>

在项目的 .csproj 文件中,因为它将优先于 tsconfig.json 文件 并重新启动visual studio,错误不再存在。

【讨论】:

  • 这仍然没有为我解决问题,即使在重新启动 VS 之后也是如此。
  • @Ageonix 在这里也一样。我已经尝试了所有建议的修复。巴克斯。
  • 这一次似乎解决了这个问题。有人评论了这篇文章,我把它放回去,它似乎工作了。现在我需要找出为什么首先将其注释掉。
  • 编辑器中的下划线消失了,但它仍然出现在错误列表中。无论如何要清除这些警告?
【解决方案2】:

同样的问题,这让我发疯了。
添加项目的 .csproj 文件

<ItemGroup>
    <Content Include="ClientApp\tsconfig.json">
      <CopyToOutputDirectory>Never</CopyToOutputDirectory>
    </Content>
  </ItemGroup>

https://github.com/Microsoft/TypeScript/issues/25823

【讨论】:

  • 打开 .csproj 右键单击​​项目然后单击 Edit *.csproj
  • VS 2019 中出现同样的问题,这是可行的解决方案
【解决方案3】:

在您的 .csproj 中,添加以下 PropertyGroup 以抑制实验性装饰器错误(撰写本文时为 1219)。之后您可能需要重新加载您的项目。 这也适用于 VS 2019。

    <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
        <NoWarn>1219;</NoWarn>
    </PropertyGroup>

    <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
        <NoWarn>1219;</NoWarn>
    </PropertyGroup>

【讨论】:

  • 对我没用,Elanor-L 的回答有效
猜你喜欢
  • 1970-01-01
  • 2020-12-12
  • 2017-04-25
  • 2018-12-03
  • 1970-01-01
  • 2018-09-04
  • 1970-01-01
  • 2012-01-28
  • 2017-08-08
相关资源
最近更新 更多