我试图用接口破坏分配,但是不能这样写。
interface TYPE {
id?: number;
type?: string;
}
const e = {
'id': 123,
'type': 'type_x',
'other1': 'other_x1',
'other2': 'other_x2'
}
const {...foo, ...others}: {foo: TYPE, others: any} = e;
console.log(foo.id, foo.type) // expected: 123, 'type_x'
console.log(others.other1, others.other2) // expected: other_x1, 'other_x2'