我有这个结构:
dts/
my-types.d.ts
lib/
a.ts
a.d.ts
b.ts
b.d.ts
a.ts 和 b.ts 都引用了某种类型,我们称之为IFoo
。
因为他们共享IFoo
,所以我想将该声明放在共享位置,所以我放入IFoo
了 dts/my-types.d.ts。
看起来像这样:
interface IFoo {
[key: string]: any
}
有道理吗?
但我遇到的问题是,虽然IFoo
在 a.ts、b.ts 和 c.ts 中被识别,但一旦创建了我的声明文件,在
a.d.ts
b.d.ts
IFoo
在这些文件中再也找不到。例如,在我的 d.ts 文件之一中:
declare var _default: (depList: string[], depContainerObj: IFoo) => Promise<any>;
export = _default;
并且IFoo
找不到。这是为什么?我怎样才能解决这个问题?
这里有一个线索!
当我改变这个:
interface IFoo {
[key: string]: any
}
对此:
export interface IFoo {
[key: string]: any
}
现在情况反过来了——我的 d.ts 文件可以看到界面,但我的 .ts 文件不能!到底是怎么回事?