tolking / element-pro-components

A component library for Vue 3 base on element-plus
https://tolking.github.io/element-pro-components
MIT License
261 stars 40 forks source link

部分 Vue 版本下,组件没有类型提示,全部被视为 any 类型,无属性提示 #522

Closed QinHang-Git closed 1 week ago

QinHang-Git commented 1 week ago

Describe the bug

你好,我在我的组件库中遇到一个问题,好像在您的组件库中也有相同的问题,但是我不确定。您有时间的话,可以看一下这个问题: 由于二次封装的组件库在编译的时候依赖了vue,我看到,您的组件库编译时,vue版本是 3.4.21。 但是在使用的时候,如果 vue 版本是 3.3.0(某些3.3.x都有可能有问题) 的时候,组件会被视为 any,从而在添加属性的时候,没有ts提示。

PixPin_2024-06-26_14-38-59

我之前看,是因为组件库编译出来的 .d.ts 文件中,用到了这个类型 import("vue").PublicProps ,但是在 低版本的 vue 中,并没有PublicProps 这个类型,导致使用的时候组件变成 any。

PixPin_2024-06-26_14-40-12

我尝试在编译组件库的时候,使用 vue 3.3.x ,但是如果在使用的过程中,版本为 3.4.15的时候,会出现一些 Ref 等其他的一些类型问题。

总之,编译组件库的时候的vue版本,和使用组件库的时候的 vue版本,如果不一致,会出现很多意想不到的问题。

同时, element plus 版本不一致的时候,也会有一些问题,例如 更换国际化语言的时候,会有不生效的问题

这个版本问题困扰了我很久,如果您也有类似的问题,可以私信我解决方案,谢谢。

Related version

vue 3.3.0 element-pro-components 1.3.1

Link to minimal reproduction

Steps to Reproduce the Bug

npm install vue@3.3.0

然后使用组件

<script setup lang="ts">
import { ProTable } from 'element-pro-components'
</script>

<template>
    <ProTable :data="''"  index="xx" />
</template>

Expected behavior

在 vue 3.3.0 中,目前的样子: PixPin_2024-06-26_14-56-08 没有提示 和 错误 提示。

在 vue 3.4.13中,能正确提示: PixPin_2024-06-26_14-57-45

目的想让其能够适配更多的 vue3 版本

Additional context

No response

tolking commented 1 week ago

一般来说高版本编译的库在低版本中使用出现问题的概率比较大

要想兼容低版本,构建的依赖最好是低版本的

或者更新 package.json 中的 peerDependencies 版本号,低版本用户用安装时就会报错