簡體   English   中英

VS 2013中的打字稿錯誤

[英]Typescript errors in VS 2013

我在Visual Studio 2013中使用TypeScript。我使用npm安裝tsd,然后使用tsd命令下載類型定義。 鍵入時得到智能提示,但是在鍵入行后出現紅色波浪形和錯誤“找不到符號x”(用ng,angular等替換x)。 我可以按住Control鍵單擊並轉到定義,因此顯然Visual Studio可以找到源定義,但是編譯器找不到。 下面的屏幕快照顯示了我為指令創建的.ts文件中的錯誤。 有什么想法我想念的嗎?

在此處輸入圖片說明

該文件需要引用angular.d.ts。 同樣,用於設置值的代碼也不正確。 而不是restrict: "E"例如restrict: "E" ,它應該是public 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());
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM