使用TypeScript装饰器会导致错误 [英] Using of TypeScript decorators caused errors

查看:247
本文介绍了使用TypeScript装饰器会导致错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm using TypeScript in new ASP.NET core project type.

我们积极使用装饰器.

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

Unfortunately, that causes lot of errors in VS2015 output:

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

要消除这些错误消息很简单,定期 ASP.NET项目修改*.csproj文件.

That is quite simple to get rid of these error messages in regular ASP.NET projects modifying *.csproj file.

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

But ASP.NET Core project does not use .csproj, it uses .xproj instead.

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

So, how to allow experimental TypeScript decorators support in VS2015 in ASP.NET Core project?

您可能会在示例github rep中找到最简单的项目,该项目会重现问题

You may find simplest project which reproduces the problem in sample github rep

推荐答案

  1. 右键单击您的项目> Add> New Item.
  2. 从以下位置选择Client-side 左侧菜单.
  3. 添加新的TypeScript JSON Configuration File.将其保留为默认名称tsconfig.json.
  4. 打开tsconfig.json.在complierOptions部分中,添加"experimentalDecorators": true.
  5. "exclude"部分中删除"wwwroot".
  6. 建立并享受.
  1. Right click on your project > Add > New Item.
  2. Pick Client-side from the left hand menu.
  3. Add a new TypeScript JSON Configuration File. Leave it as the default name of tsconfig.json.
  4. Open tsconfig.json. In the complierOptions section, add "experimentalDecorators": true.
  5. Remove "wwwroot" from the "exclude" section.
  6. Build and enjoy.

出于完整性考虑,这是我的tsconfig.json文件:

Here is my tsconfig.json file for completeness:

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

这篇关于使用TypeScript装饰器会导致错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆