使用get set“退出代码1”编译TypeScript错误代码 [英] Compiling TypeScript error code with get set "exited with code 1"
问题描述
get topLeft() { return this._topLeft; }
set topLeft(value) { this._topLeft = value; Recalc(); }
以上代码适用于TypeScript Play,但编译时收到构建错误
它来自Visual Studio 2012 错误退出代码1
The above code works find in TypeScript Play, but I received build error
when compiling it from Visual Studio 2012 error "exited with code 1"
有没有人尝试get,在TypeScript中设置并构建成功?
Does anyone try get,set in TypeScript and build successfully?
推荐答案
你需要定位ECMAScript v5,即传递 -target ES5
编译器的参数。这需要在项目文件目标配置中设置。
You'll need to target ECMAScript v5, ie pass the -target ES5
argument to the compiler. This needs to be set in the project files target configuration.
我不知道VS是否有任何内置的机制来编辑目标配置,所以我只能告诉你如何手动完成。只需打开 .csproj
项目文件,查找TypeScript编译器命令所在的目标
节点,然后添加 -target ES5
参数。
I don't know if VS has any built in mechanims for editing target configurations, so i can only tell you how to do it manually. Simply open your .csproj
project file, look for the Target
node where the TypeScript compiler command is located, and add the -target ES5
argument.
在我的配置中,它看起来像这样:
In my config it looks like this:
<Target Name="BeforeBuild">
<Exec Command=""$(PROGRAMFILES)\Microsoft SDKs\TypeScript\0.8.0.0\tsc" -target ES5 @(TypeScriptCompile ->'"%(fullpath)"', ' ')" />
</Target>
更新
从版本0.8.1.0开始,硬编码版本依赖项被删除,并且添加了对源映射的支持,因此默认情况下目标
节点现在看起来像这样:
As of version 0.8.1.0, the hardcoded version dependency was removed and support for source maps was added, and so the Target
node now looks like this by default:
<Target Name="BeforeBuild">
<Message Text="Compiling TypeScript files" />
<Message Text="Executing tsc$(TypeScriptSourceMap) @(TypeScriptCompile ->'"%(fullpath)"', ' ')" />
<Exec Command="tsc$(TypeScriptSourceMap) @(TypeScriptCompile ->'"%(fullpath)"', ' ')" />
</Target>
注入目标
参数仍然非常简单,只需将其放在 tsc
或 $(TypeScriptSourceMap)
之后:
Injecting the target
argument is still pretty easy, simply put it after tsc
or $(TypeScriptSourceMap)
:
<Message Text="Executing tsc --target ES5 $(TypeScriptSourceMap) @(TypeScriptCompile ->'"%(fullpath)"', ' ')" />
<Exec Command="tsc --target ES5 $(TypeScriptSourceMap) @(TypeScriptCompile ->'"%(fullpath)"', ' ')" />
这篇关于使用get set“退出代码1”编译TypeScript错误代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!