我有以下.d.ts文件
interface MyInterface {
login();
logout();
}
declare module "myOtherModule" {
export = MyInterface
}
现在在我的.ts文件中,我包含以下内容
import { MyInterface } from '../modules/myOtherModule';
这里我得到错误“myOtherModule.d.ts”不是模块。这不应该工作吗?如果不是我如何解决这个问题?
答案 0 :(得分:0)
要解决此问题,请尝试使用 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