angularjstypescriptwebpacktypescript2.0ng-idle

import typings of package with different name


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'

Solution

  • 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)