c-scrollbar icon indicating copy to clipboard operation
c-scrollbar copied to clipboard

组件的 ts 定义存在问题

Open imengyu opened this issue 2 years ago • 0 comments

非常棒的一个组件,不过使用中有一点小问题。

使用局部导入组件,虽然组件可以成功导入使用,但是编辑器给出了错误,可能是导出组件的 ts 定义存在问题。

错误:

不能将类型“{}”分配给类型“ComponentProps<typeof import(\"d:/Code/h5-pc-app/web-app/node_modules/c-scrollbar/types/scrollbar\")>”。\n  类型“{}”缺少类型“typeof import(\"d:/Code/h5-pc-app/web-app/node_modules/c-scrollbar/types/scrollbar\")”中的以下属性: install, CScrollbar

Snipaste_2023-02-27_10-52-10

使用的代码:

<template>
    <CScrollbar>
        ↑ 这里提示错误
        ...
    </CScrollbar>
</template>

<script lang="ts" setup>
import { CScrollbar } from 'c-scrollbar';
</script>

虽然不影响使用,但是这里总提示报错,看着也是挺难受的。

我个人的解决方法:使用 vue-tsc --declaration 命令可以自动生成 vue 组件的 ts 定义,并且可以被编辑器自动识别,在组件使用的时候会有属性提示,具体您可以参考我另外一个项目的定义文件写法

Snipaste_2023-02-27_10-50-43

还是非常感谢您可以写出这么好用的组件

imengyu avatar Feb 27 '23 03:02 imengyu