【发布时间】:2017-06-08 16:46:40
【问题描述】:
就在我认为我可以控制 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';
但我看不到要导入的内容。
我能找到的其他(许多)示例似乎都没有帮助。一定很简单,就是不懂语法。
提前感谢您的帮助。
[更新] 经过一番阅读,看起来打字已经被仅使用 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.
【问题讨论】:
-
import * as JWT from 'jtw-decode';最后一行应该是
jwt-decode这是一个错字吗? -
是的,是错字。修复并添加了更多信息
-
这 3 个对我有用 npm install --save jwt-decode npm install --save @types/jwt-decode // 并通过 import * 作为 JWT from 'jwt-decode' 导入;跨度>
标签: angular typescript ionic2 typescript-typings