pet*_*erc 15 typescript ionic2 typescript-typings angular
就在我认为我控制了打字稿中的打字时,我遇到了证明相反的事情.
这次我试图使用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;
}
Run Code Online (Sandbox Code Playgroud)
IDE(VS代码)在最后一行下显示错误"[ts]全局模块导出可能只出现在顶层"export as namespace jwt_decode;
2.如何导入?
我尝试导入声明..
import { ?? } from 'jwt-decode';
Run Code Online (Sandbox Code Playgroud)
但我看不到要导入的任何内容.
我能找到的其他(很多)例子似乎都没有帮助.它必须简单,我只是不知道语法.
在此先感谢您的帮助.
[更新]经过多次阅读后,看起来打字已经被npm取代了.
所以我试过了
npm install --save jwt-decode
npm install --save @types/jwt-decode
// and import via
import * as JWT from 'jwt-decode';
Run Code Online (Sandbox Code Playgroud)
但仍然无法正确导入它.
[UPDATE2]我可以添加语句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.
Ern*_*oso 35
对我有用的解决方案是:
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);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16523 次 |
| 最近记录: |