解构时默认赋值不准确,要么改默认值,要么改类型定义。改默认值:const data: Type = { job: { position: '' }, user: { name: '' } }; const { job = { position: '' }, user } = data;该类型定义:interface Type { job: { position?: string; } // ... } // ... const { job = {}, user } = data;或者强制类型推导,但不推荐:const { job = ({} as Type['job']), user } = data;
解构时默认赋值不准确,要么改默认值,要么改类型定义。
改默认值:
该类型定义:
或者强制类型推导,但不推荐: