【问题标题】:Unable to find 'ng' in module... - broken Intellisense?无法在模块中找到“ng”... - Intellisense 损坏?
【发布时间】:2015-04-22 21:56:50
【问题描述】:

当尝试引用外部模块时,Intellisense 会吐出一个错误...

Could not find symbol 'ng' in global module

或者..

Could not find symbol 'ng' in module 'App' // my main module

..即使我正确引用了打字稿定义(使用肯定类型):

_references.ts

/// <reference path="../../typings/tsd.d.ts" />

declare var angular: ng.IAngularStatic; // unable to find in global module

SomeDirective.ts

/// <reference path="_references.ts" />

module App {
    export class SomeDirective implements ng.IDirective // unable to find in module 'App'
}

有趣的是,使用 grunt-typescript 编译 *.ts 文件可以正常工作,并且应用程序运行没有任何问题。

【问题讨论】:

    标签: javascript angularjs typescript typescript1.4


    【解决方案1】:

    您的代码库中某处有“声明模块 ng”。请将其更改为“声明模块角度”

    详情:https://github.com/borisyankov/DefinitelyTyped/pull/3851#issue-60749247

    更新

    我的意思是搜索declare module ng。应该有 zero 结果(我怀疑您的代码库不是这种情况)。

    注意:angular.d.ts 现在是 declare module angular 而不是 declare module ng

    https://github.com/borisyankov/DefinitelyTyped/blob/master/angularjs/angular.d.ts#L26

    【讨论】:

    • 我不确定我是否理解你。 ng 由 angular.d.ts 声明(绝对类型化),而不是在我的代码库中?
    • 这似乎只是部分工作。 angular-ui、ui-router 等现在很开心,但对于其他我收到的,例如'在模块'angular'中找不到符号'IDirective'。我已经将 absoluteTyped 更新到最新版本。
    • 好吧,我想我明白了。在 angularjs 的 typescript 定义中,有一个名为 angular 的模块,其中包含我需要的所有接口。但是,还有一个全局变量声明为angular,它的类型为 IAngularStatic。因此,当我尝试在模块angular 中引用接口时,Intellisense 假定我指的是变量,因此无法找到接口。当悬停在angular 上时,它清楚地表明它是IAngularStatic 类型而不是模块。这是故意的吗?看起来从ng 重命名为angular 确实破坏了一些东西。 ://
    • 我遇到了这个问题,因为我的解决方案中仍然有一个角度转换类型定义文件,它定义了模块“ng”。用新版本替换这个文件为我解决了这个问题。 github.com/borisyankov/DefinitelyTyped/blob/master/…
    【解决方案2】:

    我遇到了完全相同的问题。我将类型“declare namespace angular”替换为“declare module angular”,现在一切都很好!

    输入来自这里:https://github.com/DefinitelyTyped/DefinitelyTyped

    我已经包含了这个文件 angular.d.ts (/// )

    【讨论】:

      猜你喜欢
      • 2017-08-24
      • 1970-01-01
      • 2017-06-08
      • 2022-12-22
      • 1970-01-01
      • 2019-05-11
      • 1970-01-01
      • 1970-01-01
      • 2021-12-03
      相关资源
      最近更新 更多