[英]Typescript errors in VS 2013
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. 我在Visual Studio 2013中使用TypeScript。我使用npm安装tsd,然后使用tsd命令下载类型定义。 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). 键入时得到智能提示,但是在键入行后出现红色波浪形和错误“找不到符号x”(用ng,angular等替换x)。 I can control-click and go to the definition so obviously Visual Studio can find the source definitions, but the compiler cannot. 我可以按住Control键单击并转到定义,因此显然Visual Studio可以找到源定义,但是编译器找不到。 Screenshot below shows the errors in a .ts file I created for my directive. 下面的屏幕快照显示了我为指令创建的.ts文件中的错误。 Any ideas what I'm missing? 有什么想法我想念的吗?
The file needs to reference angular.d.ts. 该文件需要引用angular.d.ts。 Also the code for setting the values is incorrect. 同样,用于设置值的代码也不正确。 Instead of restrict: "E"
for example, it should be public restrict = "E";
而不是restrict: "E"
例如restrict: "E"
,它应该是public restrict = "E";
. 。 The colon tells Typescript it's a type definition. 冒号告诉Typescript这是一个类型定义。
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. 我很好奇,尽管为什么我需要angular.d.ts引用,以及为什么tds.d.ts无法使用,因为它反过来又会引用angular.d.ts。 Is it typical to put a reference to the d.ts file at the top of every angular file? 通常在每个角度文件的顶部都引用d.ts文件吗? If so that could be quite a bit for my project with over 150 angularjs files. 如果是这样的话,这对于我的150多个angularjs文件的项目来说可能是相当多的。
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());
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.