【发布时间】:2019-04-18 19:56:19
【问题描述】:
我的文件 src/auth/ManagementAPI.ts 使用 Auth0。我需要使用自己的声明文件并创建了src/@types/auth0.d.ts。
但是,当我运行 ts-node 时,我收到了这个错误:
TSError: ⨯ Unable to compile TypeScript:
auth/ManagementAPI.ts(1,69): error TS7016: Could not find a declaration file for module 'auth0'. '/Users/danrumney/WebstormProjects/ohana/node_modules/auth0/src/index.js' implicitly has an 'any' type.
Try `npm install @types/auth0` if it exists or add a new declaration (.d.ts) file containing `declare module 'auth0';
我已更新我的 tsconfig.json 文件以包括:
"typeRoots": [
"./node_modules/@types",
"./src/@types"
]
我的声明文件是这样的:
declare module 'auth0' {
/*...*/
}
为什么没有收到这份声明?
我在这里创建了一个示例存储库:https://bitbucket.org/ohanapediatrics/so-demo/src/master/
【问题讨论】:
-
您有示例 repo 还是可以在 stackblitz 上创建示例?
-
您的 auth0 声明文件名是
auth0.d.ts在您的./src/@types目录中吗?好的做法是将您的第三方库本地声明文件放在./types目录中。您甚至不必在配置中添加它,它会自动解析。 -
更新:错误是当我使用
ts-node,而不是tsc -
添加了 git repo:bitbucket.org/ohanapediatrics/so-demo/src/master
标签: typescript ts-node