【问题标题】:Using of TypeScript decorators caused errors使用 TypeScript 装饰器导致错误
【发布时间】:2016-02-17 15:01:23
【问题描述】:

我在新的 ASP.NET 核心项目类型中使用 TypeScript。

我们积极使用decorators

不幸的是,这会导致 VS2015 输出中出现很多错误:

Error   TS1219  Experimental support for decorators is a feature that is subject to change in a future release.
Specify '--experimentalDecorators' to remove this warning.  
WebApplication2 d:\documents\visual studio 2015\Projects\WebApplication2\src\WebApplication2\wwwroot\sources\app.ts 9   Active

摆脱in regular ASP.NET projects修改*.csproj文件的这些错误消息非常简单。

但是 ASP.NET Core 项目不使用.csproj,而是使用.xproj

那么,如何在 ASP.NET Core 项目中允许 VS2015 中的实验性 TypeScript 装饰器支持?


您可能会找到最简单的项目来重现问题in sample github rep

【问题讨论】:

    标签: typescript visual-studio-2015 asp.net-core


    【解决方案1】:
    1. 右键单击您的项目 > Add > New Item
    2. 从中选择Client-side 左侧菜单。
    3. 添加一个新的TypeScript JSON Configuration File。将其保留为默认名称 tsconfig.json
    4. 打开tsconfig.json。在complierOptions 部分,添加"experimentalDecorators": true
    5. "exclude" 部分中删除"wwwroot"
    6. 构建并享受。

    为了完整起见,这是我的tsconfig.json 文件:

    {
      "compilerOptions": {
        "noImplicitAny": false,
        "noEmitOnError": true,
        "removeComments": false,
        "sourceMap": true,
        "target": "es5",
        "experimentalDecorators": true
      },
      "exclude": [
        "node_modules"
      ]
    }
    

    【讨论】:

    • 正确答案!只是对排除的评论:您(或本例中的操作员)不应该在 wwwroot 文件夹中拥有 *.ts 文件,因为 ti 是公开的。其目的是将所有源文件放在项目根目录中,并使用 gulp 或 grunt 编译 *.ts 文件并将编译后的 *.js 文件移动到 wwwroot
    • 感谢您的解决方案,它在 VS2015 Update 1 中运行良好(但没有 Update 1 就无法运行,这就是我们错过此解决方案的原因 :))
    • 您好,我收到此错误“无法获取未定义或空引用的属性 'compilerOptions'”。我使用最新的 VS 2015.1 和 VS 的最新 TS 插件。这是代码......这是一个hello world应用程序,仅此而已dropbox.com/s/2lv2rjdvv1op3an/a1.zip?dl=0
    猜你喜欢
    • 1970-01-01
    • 2021-01-23
    • 2016-03-27
    • 1970-01-01
    • 2020-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多