【发布时间】:2019-01-04 15:59:42
【问题描述】:
我有一个全局类型文件,我在其中定义我的类型、变量等...
现在项目结构是这样的:
trunk
typings
index.d.ts
src
Example.ts
Example.d.ts
tsconfig.json
在index.d.ts 我想说
declare type userInfo = {
username: string,
password: string,
}
但是在Example.d.ts 中,当我直接使用userInfo 时,IDE 说它找不到名称,而 tsc 编译器没有显示错误。
declare class Something {
...
getUserInfo: () => userInfo; // <--- this is highlighted red
}
有趣的是,当我在Example.ts 中使用userInfo 时,没有突出显示的错误。
另一个有趣的事情是当我go to the declaration 它跳到index.d.ts 中的正确行
我不导入这两个文件中的类型,因为它们是global 类型。
我的tsconfig 文件如下:
{
"compilerOptions": {
...
"typeRoots": ["./typings"],
...
},
...
}
可能是什么问题?
【问题讨论】:
-
我可以在 Visual Studio Code 中重现这一点。看起来当 Example.ts 存在时,Example.d.ts 不再被视为项目的一部分;
tsc甚至没有阅读它(这解释了那里没有错误),当我在 Visual Studio Code 中打开它时,它看不到其他文件。我不认为用户应该同时拥有 Example.ts 和 Example.d.ts。为什么两个都有? -
您可以将 ///
添加到您的 Example.d.ts 文件中。我建议您向github.com/Microsoft/TypeScript/issues 提交错误。
标签: typescript types import tsconfig