13
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?

Fenton
  • 241,084
  • 71
  • 387
  • 401
DexDude
  • 153
  • 1
  • 1
  • 5

2 Answers2

19

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;', ' ')" />
ndm
  • 59,784
  • 9
  • 71
  • 110
  • 1
    You're welcome :) Please note that it's recommended to mark answers that solved the problem in question as accepted (the little checkmark next to it), it's not only about reputation, but also helps others to pick the right information (assuming there are more answers), it's an indicator for other questioners and respondents that the question is solved, and others will be more encouraged to answer your questions when they see that it won't be for nothing. – ndm Oct 08 '12 at 12:12
  • my BeforeBuild target has a Exec Command=tsc$(TypeScriptSourceMap) @... line rather than the "$(PROGRAMFILES)... one you mention. Did I install something incorrectly? Do you know where to put the ES5 target with that style of Exec Command? – GaryB96 Jan 14 '13 at 20:31
  • I guess you are using a newer version, my description is related to version 0.8.0.0, the initial preview/alpha version. I can't test it right now, but it looks like this should work: `tsc --target ES5 $(TypeScriptSourceMap) ...` I'll check that later and will update my answer appropriately. – ndm Jan 14 '13 at 23:35
9

As of 0.8.2 has had another change. Some of the common TypeScript build stuff was moved from your .csproj to an external build file. Like so:

<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets" />

Your .csproj still gets to set some arguments on the TypeScript build by including them as elements in the build. one of those element is the ES version. The template created two groups for me, one for debug and one for release:

  <PropertyGroup Condition="'$(Configuration)' == 'Debug'">
    <TypeScriptTarget>ES3</TypeScriptTarget>
    <TypeScriptIncludeComments>true</TypeScriptIncludeComments>
    <TypeScriptSourceMap>true</TypeScriptSourceMap>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)' == 'Release'">
    <TypeScriptTarget>ES3</TypeScriptTarget>
    <TypeScriptIncludeComments>false</TypeScriptIncludeComments>
    <TypeScriptSourceMap>false</TypeScriptSourceMap>
  </PropertyGroup>

for the desired effect just change the ES3 to ES5

For deeper understanding of how this eventually ends up as part of the call to the TypeScript compiler have a look in the Microsoft.TypeScript.targets file.

Good luck,

Asher Barak
  • 171
  • 2
  • 8
  • after I edited the TypeScriptTarget to ES5 I get the error: `"tsc.exe" exited with code 1.` Any ideas? – daniel Oct 05 '13 at 12:24