解决vue3 defineProps 引入定义的接口报错

问题遇到的现象

在setup语法糖使用了defineProps,然而在定义类型的时候一旦将接口暴露出去引用就发生了报错

问题相关代码

interface Props {
 /* ... */
}
export {
 type Props
}
<script setup lang="ts">
 import { Props } from '.'
 const props = defineProps<Props>()
</script>

运行结果及报错内容

[@vue/compiler-sfc] type argument passed to defineProps() must be a literal type, or a reference to an interface or literal type.

我的解答思路和尝试过的方法

在组件中直接定义接口就不会报错,

我想要达到的结果

将接口封出去进行引用

作者:mycn原文地址:https://segmentfault.com/q/1010000042014549/a-1020000042017608

%s 个评论

要回复文章请先登录注册