2015-12-21 142 views
0

我在Visual Studio 2013中使用TypeScript。我使用npm安裝tsd,然後使用tsd命令下載類型定義。打字時我得到了intellisense,但是在輸入一行後,我得到了紅色的波浪曲線,並且出現「找不到符號x」的錯誤(用ng,angular等代替x)。我可以通過按住Control鍵並進入定義,Visual Studio可以找到源定義,但編譯器不能。下面的截圖顯示了我爲我的指令創建的.ts文件中的錯誤。任何想法我失蹤?VS 2013中的Typescript錯誤

enter image description here

+1

嘗試引用angular.d.ts –

+0

已嘗試了,我得到一個工具提示說不必要的重複引用。對angular.d.ts的引用在tsd.d.ts中 –

+0

從github檢查你的ts編譯器版本和angular.d.ts版本 –

回答

0

文件需要引用angular.d.ts。此外,用於設置值的代碼不正確。例如,它應該是public restrict = "E";而不是restrict: "E"。冒號告訴Typescript它是一個類型定義。

我很好奇,爲什麼我需要angular.d.ts引用以及爲什麼tds.d.ts不起作用,因爲它反過來會引用angular.d.ts。在每個角度文件的頂部添加對d.ts文件的引用是否是典型的?如果是這樣的話,我的項目可能會超過150個angularjs文件。

這裏是最後的工作代碼:

///<reference path="../../../typings/angularjs/angular.d.ts" /> 

module eStore.PromoCode { 
    export class PromoCodeDirective implements ng.IDirective { 
     public restrict = "E"; 
     public templateUrl = "Scripts/Checkout/PromoCode/promoCode.html"; 
     public scope = {}; 
     public controller = "PromoCodeController as vm"; 

     static factory(): ng.IDirectiveFactory { 
      return() => new PromoCodeDirective(); 
     } 
    } 

    angular.module("eStoreCheckout").directive("dccPromoCode", PromoCodeDirective.factory()); 
}