2012-10-10 39 views
28

瞄準ES5與打字稿我想使用Visual Studio Express中的打字稿的get/set語法網站。我如何啓用此功能。編譯時我目前得到這個錯誤;針對ES5或當在Visual Studio

屬性訪問器只提供更大

正在編譯的文件具有的TypeScriptCompile構建行動。我不知道如何從Visual Studio中添加必要的編譯器開關。

任何幫助,將不勝感激。

回答

19

您需要將-target ES5傳遞給編譯器。該編譯是使用項目文件中的msbuild任務觸發的。你的項目文件可能有一個「TypeScriptCompile」目標,比如onr波紋管,只要確保目標參數通過。下面是一個例子:

<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> 
+0

這樣做。謝謝。 – Ezward

2

用於指示TSC.EXE生成ES5兼容碼的開關是--target ES5(注意雙破折號)。

每個項目都有一個名爲[某件事]的.csproj(C#案例項目)文件。使用記事本打開該文件,並尋找Target xml元素。通過添加--target ES5來更改exec命令。

前:

<Exec Command="&quot;$(PROGRAMFILES)\Microsoft SDKs\TypeScript\0.8.0.0\tsc&quot; @(TypeScriptCompile ->'&quot;%(fullpath)&quot;', ' ')" /> 

後:

<Exec Command="&quot;$(PROGRAMFILES)\Microsoft SDKs\TypeScript\0.8.0.0\tsc&quot; --target ES5 @(TypeScriptCompile ->'&quot;%(fullpath)&quot;', ' ')" /> 
+0

這有效。謝謝。 – Ezward

+0

這是我結束了。這包括ES5目標,AMD模塊和源映射的標誌。基本上,你想要瀏覽器開發的東西。 <目標名稱= 「BeforeBuild」> 」 " %(fullpath)"','')「/> – Ezward

1

使用Studio的2012年,項目模板類型打字稿的打造,在項目的csproj文件設置爲ES3

ES3

將其更改爲ES3至ES5,保存並重新加載項目。

+0

我做到了這一點,現在我得到錯誤'」tsc.exe「退出代碼爲1.' – daniel

20

這與打字稿0.8.2改變。

<TypeScriptTarget>ES3</TypeScriptTarget> 

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

參見Asher Barak answer

4

我使用Visual Studio現在在.csproj文件從改變TypeScriptTarget 2帶有Web Essentials的013 Update 4。 微軟已經改變了針對性的ECMAScript的版本要容易得多。

您現在可以執行以下操作:

  1. 右鍵點擊項目名稱,然後單擊屬性。
  2. 在屬性窗口中選擇「打字稿構建」
  3. 組的ECMAScript版本「的ECMAScript 5」。

我相信ECMAScript 5目前是默認的。您目前也可以選擇ECMAScript 3或ECMAScript 6作爲目標。

+1

這是現在最好的答案 – Pakman