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

Bug: Not resolve exports from module entry file #3

Open
Hieuzest opened this issue Jun 23, 2023 · 6 comments
Open

Bug: Not resolve exports from module entry file #3

Hieuzest opened this issue Jun 23, 2023 · 6 comments
Labels
bug Something isn't working

Comments

@Hieuzest
Copy link

Hieuzest commented Jun 23, 2023

当index.ts中无导出时,esbuild将生成空的module文件,而dtsc不会作此区分,从而导致编辑器误以为导出

@shigma
Copy link
Owner

shigma commented Jun 23, 2023

没理解什么叫「导致编辑器误以为导出」

@Hieuzest
Copy link
Author

Hieuzest commented Jun 23, 2023

生成index.mjs/cjs时,esbuild只会导出index.ts中导出的符号。
在此情况下,dtsc可能生成错误的.d.ts文件,从而错误地导出了module中并没有导出的内容
而编辑器/lsp会从.d.ts文件中查找声明,得出该符号已经导出的结论,导致运行时报错

@shigma
Copy link
Owner

shigma commented Jun 23, 2023

我明白了。

这种情况并不好解决:

  1. 目前 dtsc 采取的是字符串处理的方式,并不能静态分析具体哪些导出
  2. 直接导出所有符号在很多场景下存在一些方便之处
  3. 许多手写 dts 的库也存在 dts 与实际导出不一致的情况,我认为 dtsc 这个库没有必要确保 100% 的一致性

不过 issue 仍然可以继续开着,如果之后有比较好的方案确实可以优化一下。

@shigma shigma added the bug Something isn't working label Jun 23, 2023
@Hoshino-Yumetsuki
Copy link
Contributor

Hoshino-Yumetsuki commented Feb 21, 2025

可以看看rollup-plugin-dts的实现,但是会很慢

@shigma
Copy link
Owner

shigma commented Feb 23, 2025

可以看看rollup-plugin-dts的实现,但是会很慢

确实,我最初写这玩意就是尝试了 rollup-plugin-dts 和其他各种工具都觉得太慢才做的 dtsc。

@Hoshino-Yumetsuki
Copy link
Contributor

不过可以也提供一个rollup-plugin-dts的dtsc实现,给对dts生成要求比较严格的用户

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants