我想要转换特定类型的另一个对象的一个对象,其中第一个对象的属性包含另一个对象的所有属性,但有一些额外的属性.
给出以下示例:
type person = {
name: string;
age: number;
address: string;
id: number;
}
type personWithoutId = {
name: string;
age: number;
address: string;
}
const person: person = {
name: 'John',
age: 30,
address: '123 Main St',
id: 1
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { id, ...rest } = person;
const alex: personWithoutId = rest;
这很有效,但是eslint在抱怨,我想摆脱禁用 comments 的规则.
我不能 Select delete
%的财产,因为它不是可选的.
那么,做这件事的最佳方式是什么呢?