Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typeRoots 定义了类型声明文件的位置, 为什么读不到? #56

Open
yubaoquan opened this issue Mar 22, 2019 · 0 comments
Open

Comments

@yubaoquan
Copy link
Owner

yubaoquan commented Mar 22, 2019

在声明文件中声明了一个接口如下
src/types/some-type.ts

export interface IXxx {}

并在typeRoots中配置了声明文件的位置

typeRoots: ["src/types"]

但是代码依然报错 cannot find name IXxx

问题出在export关键字上. 如果在类型声明文件中加上export, 编译器会认为这是一个module, 所以想要使用这个文件中声明的类型, 需要显式导入

import { IXxx } from 'types/some-type';

这样做显然是很恶心的. 所以不应该在类型声明文件中添加export. 这样编译器就会把声明文件中声明的接口全部编译成全局接口

另一种情况, 本地对第三方包做的声明, 需要将声明文件路径添加到配置文件中的paths

参考资料

  1. vscode can't find typeRoots type definitions
  2. typeRoots is not finding custom declaration file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant