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.
TypeScript allows converting most of the ES next features to ES3, ES5, ES6, ES2016, ES2017.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With