我试着用接口解构赋值,但不能这样写。
interface TYPE {
id?: number;
type?: string;
}
const e = {
'id': 123,
'type': 'type_x',
'other': 'other_x'
}
const {...foo}: {foo: TYPE} = e;
console.log(foo.id, foo.type) // expected: 123, 'type_x'发布于 2019-08-04 14:30:54
只需在变量上声明类型,而不使用奇怪的对象符号:
const { ...foo }: TYPE = e;然而,这是一种奇怪的复制对象的方式--通常是这样做的:
const foo: TYPE = { ...e };https://stackoverflow.com/questions/57344332
复制相似问题