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

导出 declare module "xxx" 和 declare global 定义的模块扩展支持 #240

Closed
2 tasks done
biggerstar opened this issue Jul 11, 2023 · 3 comments
Closed
2 tasks done
Labels
enhancement New feature or request

Comments

@biggerstar
Copy link
Contributor

Description

当前测试不支持导出 declare module "xxx" 和 declare global , 而这两个也是拓展其他库常用定义,速度支持-_-

测试导出代码

// 为vue库定义一个名为Test新类型 
export declare module "vue"{
    export type Test = { newField : string }
}

遇到的情况

通过vite build 编译后无法在构建产物 xxx.d.ts中找到上面定义,此时也是无法通过 import { Test } from 'vue' 引入拓展的新类型

Suggested solution

.

Alternative

No response

Additional context

No response

Validations

  • Read the FAQ.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
@qmhc
Copy link
Owner

qmhc commented Jul 12, 2023

这是一个 api-extractor 已知的问题:microsoft/rushstack#2090 microsoft/rushstack#1709

目前你可以参考 VueRouter 的做法 或暂时不使用 rollupTypes 功能。

@qmhc qmhc added the pending Need further confirmation label Jul 12, 2023
@biggerstar
Copy link
Contributor Author

我现在使用了vue-router的做法,但是该做法不够优雅,因为必须准确控制文本切割合并的行数。
后面发现了有这么个仓库,看下可以给您参考下,将其外部配置字符串指向的文件 解析成ast语法树,之后再输出(feature: 给出一个配置合并到同一个文件或者全局定义的d.ts单独输出一个文件 )
您可以考虑后面加上该功能,我觉得手动解析的话可能是当前的最佳实践,也能使vite-plugin-dts更加完美 rollup-plugin-add-global-ts

@biggerstar
Copy link
Contributor Author

我花了点时间写了解决这个问题的通用插件 vite-plugin-copy-dts

@qmhc qmhc added enhancement New feature or request and removed pending Need further confirmation labels Oct 24, 2023
@qmhc qmhc closed this as completed in 39606bd Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants