导入具有不同名称的包类型

import typings of package with different name

我正在将现有项目转换为打字稿。该项目正在使用包 ng-idle and it has @types package with name angular-idle 并且文件 @types/angular-idle/index.d.ts 包含

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

如何导入这个包

   import * as ngIdle from 'angular-idle'

   import * as ngIdle from 'ng-idle'

有几种方法可以做到这一点

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

您甚至可以在导入时重命名命名空间

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

如果您已经导入 angular

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

(或直接使用angular.idle