在 Visual Studio 中使用 TypeScript 以 ES5 为目标 [英] Targeting ES5 with TypeScript in Visual Studio

查看:22
本文介绍了在 Visual Studio 中使用 TypeScript 以 ES5 为目标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Visual Studio Express for Web 中的 TypeScript 中使用 get/set 语法.我如何启用此功能.我目前在编译时收到此错误;

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;

属性访问器仅在面向 ES5 或更高版本时可用

Property accessors are only available when targeting ES5 or greater

正在编译的文件具有 TypeScriptCompile 的构建操作.我不知道如何从 Visual Studio 中添加必要的编译器开关.

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.

任何帮助将不胜感激.

推荐答案

您需要将 -target ES5 传递给编译器.使用项目文件中的 msbuild 任务触发编译.您的项目文件可能有一个TypeScriptCompile"目标,就像下面的 onr 一样,只需确保传递了目标参数.下面是一个例子:

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

这篇关于在 Visual Studio 中使用 TypeScript 以 ES5 为目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆