【发布时间】:2021-09-13 15:30:46
【问题描述】:
我有以下 User 类型的代码,它具有可选类型 Address,我想在一行中解构。但是,当我尝试时,我收到一条错误消息:
“地址”类型上不存在“街道”属性 |未定义'
Click here to see the Typescript playground of the code provided bellow
type User = {
age: number;
address?: Address;
}
type Address = {
street?: string;
}
const user: User = {
age: 22,
address: {}
}
const {age, address: {street}} = user
这里 street 在类型 Address | undefined 上不存在
【问题讨论】:
标签: javascript typescript typescript-typings typescript2.0