使用TypeScript装饰器会导致错误 [英] Using of TypeScript decorators caused errors
问题描述
我在新的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
推荐答案
- 右键单击您的项目>
Add
>New Item
. - 从以下位置选择
Client-side
左侧菜单. - 添加新的
TypeScript JSON Configuration File
.将其保留为默认名称tsconfig.json
. - 打开
tsconfig.json
.在complierOptions
部分中,添加"experimentalDecorators": true
. - 从
"exclude"
部分中删除"wwwroot"
. - 建立并享受.
- Right click on your project >
Add
>New Item
. - Pick
Client-side
from the left hand menu. - Add a new
TypeScript JSON Configuration File
. Leave it as the default name oftsconfig.json
. - Open
tsconfig.json
. In thecomplierOptions
section, add"experimentalDecorators": true
. - Remove
"wwwroot"
from the"exclude"
section. - 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屋!