Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiling TypeScript error code with get set "exited with code 1"

get topLeft()      { return this._topLeft;             }

set topLeft(value) {  this._topLeft = value; Recalc(); }

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"

Does anyone try get,set in TypeScript and build successfully?

like image 296
DexDude Avatar asked Oct 07 '12 16:10

DexDude


1 Answers

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.

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="&quot;$(PROGRAMFILES)\Microsoft SDKs\TypeScript\0.8.0.0\tsc&quot; -target ES5 @(TypeScriptCompile ->'&quot;%(fullpath)&quot;', ' ')" />
</Target>

Update

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 ->'&quot;%(fullpath)&quot;', ' ')" />
    <Exec Command="tsc$(TypeScriptSourceMap) @(TypeScriptCompile ->'&quot;%(fullpath)&quot;', ' ')" />
</Target>

Injecting the target argument is still pretty easy, simply put it after tsc or $(TypeScriptSourceMap):

<Message Text="Executing tsc --target ES5 $(TypeScriptSourceMap) @(TypeScriptCompile ->'&quot;%(fullpath)&quot;', ' ')" />
<Exec Command="tsc --target ES5 $(TypeScriptSourceMap) @(TypeScriptCompile ->'&quot;%(fullpath)&quot;', ' ')" />
like image 149
ndm Avatar answered Oct 10 '22 04:10

ndm