【发布时间】:2022-01-14 20:14:16
【问题描述】:
我定义了以下类型,我正在尝试与 ref 一起使用,并且最初不想定义所有道具默认值,但我是 TS 错误:No Overload Matches this call强>
interface EmailReminder {
bcc_emails: string[] | null;
cc_emails: string[];
from_email: string;
message: string;
offset_days: number;
subject: string;
to_emails: string[];
sent_at: string | Date;
uuid: string;
}
当我尝试使用 Vue 3 ref 创建反应变量时,通过传递我的类型代替泛型,打字稿会生气并引发以下错误。
const reminder = ref<EmailReminder>({
to_emails: [],
cc_emails: [],
message: '',
subject: '',
});
谁能告诉我我在这里做错了什么,我不想让某些属性成为可选的,并且事件不想使用as 来删除它们。
【问题讨论】:
-
您必须将它们设为可选,否则它们的类型不同。
标签: typescript vue.js vuejs3