如何将 jwt-decode 类型定义导入 Typescript (Ionic 2)

How to import the jwt-decode type definition into Typescript (Ionic 2)

就在我认为我可以控制 Typescript 中的打字时,我遇到了相反的情况。

这次我尝试使用jwt-decode。我已经通过命令 typings i dt~jwt-decode --save

安装了类型定义

两个问题

1. 当我查看 index.d.ts 时,我看到以下内容

    declare module 'jwt-decode' {
        namespace JwtDecode {
        interface JwtDecodeStatic {
            (token: string): any;
        }
    }

    var jwtDecode: JwtDecode.JwtDecodeStatic;
    export = jwtDecode;
    export as namespace jwt_decode;
    }

IDE (VS Code) 显示错误 "[ts] 全局模块导出可能只出现在顶层" 最后一行 export as namespace jwt_decode;

2.如何导入这个?

我试试导入语句..

   import { ??  } from 'jwt-decode';

但我看不到要导入的任何内容。

None 我能找到的其他(许多)例子似乎有帮助。一定很简单,就是不懂语法。

在此先感谢您的帮助。

[更新] 经过更多的阅读,看起来打字已经被 npm 取代了..

所以我尝试了

npm install --save jwt-decode
npm install --save @types/jwt-decode

// and import via
import * as JWT from 'jwt-decode';

但还是无法正确导入。

[更新2] 我可以添加语句 let t = jwt-decode("aaa"); 并查看签名,但有以下 IDE 错误

[ts] 'jwt_decode' refers to a UMD global, but the current file is a module. Consider adding an import instead.

对我有用的解决方案是:

npm install --save jwt-decode
npm install --save @types/jwt-decode

// and import via
import * as JWT from 'jwt-decode';

// use JWT() for decode. Not jwt-decode() !!
let t = JWT(token);