Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Targeting ES5 with TypeScript in Visual Studio

Tags:

typescript

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.

like image 623
Ezward Avatar asked Oct 10 '12 02:10

Ezward


People also ask

Does TypeScript support ES5?

TypeScript allows converting most of the ES next features to ES3, ES5, ES6, ES2016, ES2017.

Which command is used to manually compile a TypeScript source file into ES5 if using TypeScript?

Here, you will learn how to compile a TypeScript project and also learn about tsconfig. json. As you know, TypeScript files can be compiled using the tsc <file name>. ts command.

Can I use Visual Studio for TypeScript?

For projects developed in Visual Studio 2022, we encourage you to use the TypeScript NuGet or the TypeScript npm package for greater portability across different platforms and environments. For more information, see Compile TypeScript code using NuGet and Compile TypeScript code using tsc.


1 Answers

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

like image 114
Ian Boyd Avatar answered Sep 20 '22 08:09

Ian Boyd