any86 / vue-error

常见vue3报错解决
2 stars 0 forks source link

不能将类型“{}”分配给类型“(props: Readonly<Props>) => KV<unknown>”。 类型“{}”提供的内容与签名“(props: Readonly<Props>): KV<unknown>”不匹配。ts(2322) #7

Open any86 opened 2 years ago

any86 commented 2 years ago
interface Props {
  modelValue: KV;
  items?: Item[];
}

const props = withDefaults(defineProps<Props>(),{
 // 🔥 问题就出在这里 ↓
  modelValue:{},
});

不要忘记了引用型数据作为默认值, 要嵌套一层函数, 修改为:

const props = withDefaults(defineProps<Props>(),{
  modelValue:()=>({}),
});