【问题标题】:Typescript Auth0 moduleTypescript Auth0 模块
【发布时间】:2017-05-06 10:27:28
【问题描述】:
我有以下 .d.ts 文件(摘录)
declare const Auth0: Auth0Static;
declare module "auth0-js" {
export = Auth0
}
现在在我的 .ts 文件中,我正在使用以下内容
import { Auth0 } from 'auth0-js';
我收到以下错误
auth0-js 没有导出成员 Auth0
这里出了什么问题?
【问题讨论】:
标签:
typescript
module
auth0
【解决方案1】:
auth0-js 库不会导出任何名为 Auth0 的内容。
如果您只想导入所有内容,请将导入更改为 import * as Auth0 from 'auth0-js'。否则,您可以导入单个导出,例如 import { WebAuth } from 'auth0-js';
另外,你自己打字吗?否则,您可以只使用来自npm install @types/auth0-js 的现有类型。
确保您的 tsconfig.json 已配置为查找类型:
{
"compilerOptions": {
...
"typeRoots": [
"node_modules/@types"
],
...
}
}
【解决方案2】:
您可以在 index.html 中包含 auth0 脚本
在您的 auth.ts 中。你可以使用
declare var auth0: any;
这避免了打字稿可能引发的任何未找到名称的错误。
【解决方案3】:
在我们的 angular-cli 项目中,我们成功地设置了它
npm install auth0-js @types/auth0-js --save
并导入您需要的路径,例如import { WebAuth } from 'auth0-js';