Typescript: Using angular in a .d.ts file, I get “[ts] Cannot find namespace 'angular'”

Created on 18 May 2016  ·  3Comments  ·  Source: microsoft/TypeScript

Code:

    // ngimport.d.ts:
    export declare let $anchorScroll: angular.IAnchorScrollService;
    export declare let $cacheFactory: angular.ICacheFactoryService;
    export declare let $compile: angular.ICompileService;
    export declare let $controller: angular.IControllerService;
    export declare let $document: angular.IDocumentService;
    ...

Each of the angulars above throws an error in VSCode: [ts] Cannot find namespace 'angular' \ any.

And when I import ngimport from another project, I get Error TS2503: Cannot find namespace 'angular'

typings.json:

    {
      "ambientDependencies": {
        "angular": "registry:dt/angular#1.5.0+20160517064839",
        "jquery": "registry:dt/jquery#1.10.0+20160316155526"
      }
    }

tsconfig.json:

    {
      "compilerOptions": {
        "module": "es6",
        "moduleResolution": "node",
        "noImplicitAny": true,
        "preserveConstEnums": true,
        "outDir": ".",
        "sourceMap": false,
        "target": "es6"
      },
      "files": [
        "./typings/main.d.ts",
        "./ngimport.ts"
      ]
    }

Full source: https://github.com/bcherny/ngimport

Question

All 3 comments

For anyone who finds this in the future, this was actually a typings issue. Upgrading typings to 1.x fixed it.

That link is a lie.

Was this page helpful?
0 / 5 - 0 ratings