TypeScript 3.7 版本已实现了此功能
javascript
{
// before
const street = user && user.address && user.address.street
const num = user && user.address && user.address.getNum && user.address.getNum()
const arr =
user &&
user.address &&
user.address.dataList &&
user.address.dataList[0] &&
user.address.dataList[0].details
console.log(street, num)
}
{
// now
const street2 = user?.address?.street
const num2 = user?.address?.getNum?.()
const arr2 = user?.address?.dataList?.[0]?.details
console.log(street2, num2)
}