简体   繁体   English

VS 2013中的打字稿错误

[英]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.

相关问题 是否需要在TypeScript中包含VS的java lint提示-VS-2013 - Is it needed to include the hints for java lint with Typescript , VS - 2013 使用VS 2013在Typescript中装饰AngularExceptionHandler服务 - Decorating angular exceptionHandler service in Typescript using VS 2013 VS Code中的“找不到名称&#39;x&#39;”Typescript错误不一致 - Inconsistent “Cannot find name 'x'” Typescript errors in VS Code 与ID ####的进程未在vs 2013中运行 - Process with an ID #### is not running in vs 2013 TypeScript定义文件上的编译错误 - Compilation errors on the TypeScript Definition Files 在Eclipse中使用Angular 2和TypeScript编译错误 - Compile errors with Angular 2 and TypeScript in Eclipse VS 2013标签完成打破了角度表达 - VS 2013 tag completion breaks angular expression Visual Studio 2013找不到用于angular 2项目的Typescript版本 - Visual Studio 2013 can't find version of Typescript for angular 2 project Visual Studio 2013中的Typescript中使用AngularJS“模块”声明的难度 - Difficulty with AngularJS “module” declaration in Typescript in Visual Studio 2013 具有隔离范围的Angular Typescript指令在编译时生成Typescript错误 - Angular Typescript Directive with Isolate Scope generates Typescript errors on compile
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM