vue-component-type-helpers插件获取vue3组件的props, slots, expose类型定义

595 阅读1分钟

安装依赖

pnpm add vue-component-type-helpers

使用

import Test from './components/Test.vue'
import type { ComponentExposed } from 'vue-component-type-helpers'

const exposeType = ref<null | ComponentExposed<typeof Test>>()

type Props = ComponentProps<typeof Test>
type Slots = ComponentSlots<typeof Test> 

参考资料

Cannot use InstanceType<typeof Comp<any>>> on generic components

vue-component-type-helpers - npm (npmjs.com)