关于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 {};
},
});