Reputation: 17702
I would like to use get/set syntax in TypeScript within Visual Studio Express for Web. How do I enable this. I currently get this error when compiling;
Property accessors are only available when targeting ES5 or greater
The file being compiled has a build action of TypeScriptCompile
. I don't know how to add a the necessary compiler switch from within Visual Studio.
Any help would be appreciated.
Upvotes: 31
Views: 21832
Reputation: 528
I am using Visual Studio 2013 Update 4 with Web Essentials. Microsoft has made changing the targetted ECMAScript version much easier.
You can now do the following:
I believe ECMAScript 5 is currently the default. You can at present also choose ECMAScript 3 or ECMAScript 6 as targets.
Upvotes: 5
Reputation: 256731
This has changed with TypeScript 0.8.2. You now change TypeScriptTarget
in the .csproj
file from:
<TypeScriptTarget>ES3</TypeScriptTarget>
to
<TypeScriptTarget>ES5</TypeScriptTarget>
MyApp.csproj:
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
<TypeScriptTarget>ES5</TypeScriptTarget>
<TypeScriptIncludeComments>true</TypeScriptIncludeComments>
<TypeScriptSourceMap>true</TypeScriptSourceMap>
<TypeScriptModuleKind>AMD</TypeScriptModuleKind>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<TypeScriptTarget>ES5</TypeScriptTarget>
<TypeScriptIncludeComments>false</TypeScriptIncludeComments>
<TypeScriptSourceMap>false</TypeScriptSourceMap>
<TypeScriptModuleKind>AMD</TypeScriptModuleKind>
</PropertyGroup>
See also Asher Barak answer
Upvotes: 25
Reputation: 31
Using Studio 2012, project template type TypeScript the build, in the project csproj file is set to ES3
ES3
Change it to ES3 to ES5, save it and reload the project.
Upvotes: 1
Reputation: 19
The switch for instructing the TSC.EXE to generate ES5 compatible code is --target ES5 (note the double dashes).
Each project has a file called [Something].csproj (C# project in our case). Open that file using notepad and look for Target
xml element. Change the exec command by adding the --target ES5
.
Before:
<Exec Command=""$(PROGRAMFILES)\Microsoft SDKs\TypeScript\0.8.0.0\tsc" @(TypeScriptCompile ->'"%(fullpath)"', ' ')" />
After:
<Exec Command=""$(PROGRAMFILES)\Microsoft SDKs\TypeScript\0.8.0.0\tsc" --target ES5 @(TypeScriptCompile ->'"%(fullpath)"', ' ')" />
Upvotes: 2
Reputation: 9509
You need to pass the -target ES5 to the compiler. The compilation is triggered using an msbuild task in your project file. Your project file probably has a "TypeScriptCompile" target like the onr bellow, just make sure to the target argument is passed. Here is an example:
<Target Name="TypeScriptCompile" BeforeTargets="Build">
<Message Text="Compiling TypeScript files" />
<Exec Command=""$(PROGRAMFILES)\Microsoft SDKs\TypeScript\0.8.0.0\tsc" -target ES5 @(TypeScriptCompile ->'"%(fullpath)"', ' ')" />
</Target>
Upvotes: 22