I'm using TypeScript in Visual Studio 2013. I used npm to install tsd and then am using the tsd command to download type definitions. I get intellisense when typing but then after a line is typed I get the red squiggly and an error that "could not find symbol x" (replace x with ng, angular, etc). I can control-click and go to the definition so obviously Visual Studio can find the source definitions, but the compiler cannot. Screenshot below shows the errors in a .ts file I created for my directive. Any ideas what I'm missing?
The file needs to reference angular.d.ts. Also the code for setting the values is incorrect. Instead of restrict: "E"
for example, it should be public restrict = "E";
. The colon tells Typescript it's a type definition.
I am curious though why I need the angular.d.ts reference and why tds.d.ts wouldn't work since it in turn would reference angular.d.ts. Is it typical to put a reference to the d.ts file at the top of every angular file? If so that could be quite a bit for my project with over 150 angularjs files.
Here is the final working code:
///<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());
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.