[英]typescript custom .d.ts import module does not work
我有以下.d.ts文件
interface MyInterface {
login();
logout();
}
declare module "myOtherModule" {
export = MyInterface
}
现在在我的.ts文件中,我包括以下内容
import { MyInterface } from '../modules/myOtherModule';
在这里我得到错误“myOtherModule.d.ts”不是一个模块。 这不应该工作吗? 如果不是我该怎么解决这个问题?
要解决此问题,请尝试在myOtherModule.d.ts
文件中使用:
export interface MyInterface {
login();
logout();
}
还有你的foo.ts
文件:
import { MyInterface } from '../modules/myOtherModule';
请参考官方的TypeScript模板来编写.d.ts文件。
你可以在这里找到一些例子: https : //www.typescriptlang.org/docs/handbook/declaration-files/templates.html
如果要为自定义模块或类模块编写.d.ts文件,则这些模板中有许多有用的信息。
此外,这里有很多有用的信息: https : //www.typescriptlang.org/docs/handbook/declaration-files/deep-dive.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.