下面有一个解构赋值,[invoice, customers]
中两个元素的推断类型分别是 const invoice
和 const customers
:
const [invoice, customers] = await Promise.all([
fetchInvoiceById(id),
fetchCustomers(),
]);
const invoice: {
amount: number;
id?: string | undefined;
date?: string | undefined;
status?: $Enums.InvoiceStatus | undefined;
customerId?: string | undefined;
}
const customers: {
id: string;
name: string;
email: string;
image_url: string;
}[]
现在我要把下面两个类型手动指定给 [invoice, customers]
中对应的元素,即 invoice
的类型为 InvoiceForm
,customers
的类型为 CustomerField
,语法应该怎么写?
type InvoiceForm = {
id: string;
customerId: string;
amount: number;
status: 'pending' | 'paid';
};
type CustomerField = {
id: string;
name: string;
};