vue3中如何获取组件props的ts类型

组件B里想要获得组件A的props的ts类型,要怎么获取?
不要export再import 或者提取出去

组件A

<script setup lang="ts">
interface PropsType {
    childProp1: number
    childProp2: string
    childProp3: boolean
}

defineProps<PropsType>()
</script>

组件B

<script setup lang="ts">
import Child from './Child.vue'

type ChildInstance = InstanceType<typeof Child>
</script>

image.png

怎么能从Child组件上获取它属性的ts类型

阅读 12.1k
1 个回答
type ChildProps = InstanceType<typeof Child>['$props']
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题