ts类型转换的一种偷懒写法

61 阅读1分钟
type Product = {
    id: number,
    name: string,
    count: number,
    label: string,
}

const postData = async ({ id, ...product }: Product) => {
    ...
    await request.post(url, product)
    ...
}

适用于对象中需要排除几个不需要的属性,而无需麻烦的类型转换。