import typings of package with different name

460 views Asked by At

I am converting exiting project to typescript. The project is using a package ng-idle and it has @types package with name angular-idle and the file @types/angular-idle/index.d.ts contains

declare module 'angular' {
    export namespace idle {
         ....

How do I import this package

   import * as ngIdle from 'angular-idle'

or

   import * as ngIdle from 'ng-idle'
1

There are 1 answers

4
Bruno Grieder On BEST ANSWER

There are a few ways to do this

import {idle} from 'angular'
const blah = idle.BLAH

You can even rename the namespace on import

import {idle as ng_idle} from 'angular'
const blah = ng_idle.BLAH

If you already import angular

 import * as angular from 'angular'
 import idle = angular.idle
 const blah = idle.BLAH

(or use angular.idle directly)