Skip to content

GlobalComponents 全局组件类型声明失效 #34

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

Closed
5 of 7 tasks
Vanisper opened this issue Apr 16, 2025 · 5 comments
Closed
5 of 7 tasks

GlobalComponents 全局组件类型声明失效 #34

Vanisper opened this issue Apr 16, 2025 · 5 comments

Comments

@Vanisper
Copy link
Contributor

Vanisper commented Apr 16, 2025

描述问题

当前项目 GlobalComponents 定义的全局组件类型声明全部失效。

不只是当前项目的声明失效(jsx 相关的标签组件声明是生效的),项目内部自定义的全局组件声明也全部失效。

这应该是当下版本的所有uniapp项目存在的问题!

复现

使用 pnpm create uni 创建一个干净的ts项目,自定义模板,选择安装 wot-design-uni 组件库,其他插件一律不选择安装。

保持 vue 语言插件为最新的状态,不要配置 vueCompilerOptions(由于 pnpm create uni 创建的项目会加上这个ts配置,所以需要手动去除)。

之后卸载当前项目的vue,然后再自由安装(这个时候基本会安装最新版的vue),此时会发现bug已经修复。

最小复现 https://github.com/Vanisper/uni-app-gc-bug

系统信息


基础环境信息:

  • os: Windows 10 10.0.19045
  • node: 20.18.1
  • packageManager: pnpm
  • vscode: 1.99.3
  • volar: 2.2.8

基础依赖信息:

  • vue: 3.5.13
  • vite: 5.2.8
  • @dcloudio/uni-app: 3.0.0-4050720250324001

uni-helper依赖信息:

  • @uni-helper/uni-types: 1.0.0-alpha.6
  • @uni-helper/vite-plugin-uni-components: 0.2.0

uni-helper插件信息:

  • create-uniapp-view: 2.1.0
  • uni-app-schemas-vscode: 0.9.3
  • uni-app-snippets-vscode: 0.10.5
  • uni-cloud-snippets-vscode: 0.3.0
  • uni-helper-vscode: 0.5.9
  • uni-highlight-vscode: 0.3.15
  • uni-ui-snippets-vscode: 0.6.6

使用的包管理器

pnpm

核对

贡献

  • 我愿意提交一个 PR 修复这个问题
  • 我愿意提交一个 PR 带有失败的测试(实际上只要去做就好,谢谢!)
@Vanisper
Copy link
Contributor Author

Vanisper commented Apr 16, 2025

请查阅最小复现提供的项目 https://github.com/Vanisper/uni-app-gc-bug

Image

最小化修复的步骤就是升级vue的版本!

然而由于uniapp模板项目使用的vue的版本,基本是跟随着uniapp官方模板来的,基本处于 3.4 的版本,好像没有人注意到这个问题产生的原因,是uniapp官方模板依赖的vue的版本导致的。

虽然说 3.4 左右的版本不算太低,但是这确实是当下问题产生的原因。

当然此 issues 更多是阐述类型失效的原因,因为我们好像不太好操作 vue 的版本(uniapp官方模板的众多依赖引用的还是 3.4 版本的vue),这是上游供应链的问题

@Vanisper
Copy link
Contributor Author

Vanisper commented Apr 16, 2025

再顺道提一句之前提的pr - #32

这个pr解决的是 JSX.IntrinsicElements 组件的类型提示表现不正确的问题,研究发现此类组件不同于自定义全局组件,不应该存在 DefineComponent 包裹(详见该pr的说明)。

不过旧版本的vue语言插件在借助 vueCompilerOptions.plugins 配置的情况下,被 DefineComponent 包裹的jsx组件表现确实是正常的。但是我认为当下版本如果能够不借助额外插件配置的情况下,能使类型系统正常工作,这将是最好的选择。

经过多次的测试验证得出,vueCompilerOptions.plugins 配置方案是绝对没问题的!

但是 JSX.IntrinsicElements 组件的类型问题还是需要解决一下的。

@Vanisper
Copy link
Contributor Author

Vanisper commented Apr 17, 2025

在大佬们的帮助下,定位到了当下最可能的直接原因 —— ts 的版本。

uni create 创建的项目使用的 ts 的版本基本是保持着最新的(5.8.*),最后发现 uni-typed 的 playground 的 ts 版本是 5.5.4,这个版本是没问题的。

仅作记录,待进一步研究。

回顾之前的解决办法,ts 的版本保持最新,同时需要 vue 的版本也保持更新。

@Vanisper
Copy link
Contributor Author

Vanisper commented Apr 17, 2025

这个话题没有太多的研究价值了,根本原因是随着 ts 的某些版本更新, vue 语言插件方没有捕获到关键的差异性变更而做出相应的调整。

再加上变量太多了,vue的版本、ts的版本、还有语言插件本身的版本差异性,所以各版本之间的不配合导致问题的出现是情有可原的。

解决办法就是保持 ts、vue、vue语言插件为最新版本即可,或者就是保持 [email protected]5.6.0-beta 之前,详见)、[email protected].*,vue语言插件保持最新。

调查结果数据:

@Vanisper
Copy link
Contributor Author

vuejs/language-tools#5324

已反馈相关 issue

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