关于vue3+ts中使用props进行类型限制报错的问题

报错

Type '{}' is not assignable to type '(props: Readonly<Props>) => object'.   Type '{}' provides no match for the signature '(props: Readonly<Props>): object'.

报错时的代码

//props
interface Props {
  mydata:object,
}
const props = withDefaults(defineProps<Props>(), {
  mydata:{}
});

解决后的代码

//props
interface Props {
  mydata: object;
}
const props = withDefaults(defineProps<Props>(), {
  mydata: () => {
    return {};
  },
});
posted @ 2022-09-18 12:50  xiaowei123456  阅读(2683)  评论(0编辑  收藏  举报