0

我有这个结构:

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 文件不能!到底是怎么回事?

4

1 回答 1

1

到底是怎么回事?

模块使用不一致。请尽可能使用模块,也就是没有全局变量。也一样export interface IFoo {

我的 d.ts 文件可以看到界面,但我的 .ts 文件不能!到底是怎么回事?

导入包含IFoo在每个需要它的文件中的文件,例如:

import {IFoo} from "./foo";
// now use IFoo

更多的

关于模块已经说了很多 https://basarat.gitbooks.io/typescript/content/docs/tips/outFile.html

于 2017-04-19T05:35:00.250 回答