d.ts 文件不能 "see" 类型声明
d.ts file cannot "see" type declaration
我有这样的结构:
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文件不能!怎么回事?
What is going on?
模块使用不一致。请尽可能使用模块,也就是不要使用全局变量。 export interface IFoo {
也是如此
my d.ts files can see the interface, but my .ts file cannot! What is going on?
在每个需要它的文件中导入包含 IFoo
的文件,例如a.ts:
import {IFoo} from "./foo";
// now use IFoo
更多
关于模块已经说了很多
https://basarat.gitbooks.io/typescript/content/docs/tips/outFile.html
我有这样的结构:
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文件不能!怎么回事?
What is going on?
模块使用不一致。请尽可能使用模块,也就是不要使用全局变量。 export interface IFoo {
my d.ts files can see the interface, but my .ts file cannot! What is going on?
在每个需要它的文件中导入包含 IFoo
的文件,例如a.ts:
import {IFoo} from "./foo";
// now use IFoo
更多
关于模块已经说了很多 https://basarat.gitbooks.io/typescript/content/docs/tips/outFile.html