我得到响应registryReportSettings
从服务器:
this.getRegistrySettings(registry.Id).subscribe((registryReportSettings: { extended: ReportPropertiesRequest }) => {
const { objectProperties, reportProperties, textProperties } = registryReportSettings?.extended;
}
如果是null
,我得到一个错误:
TypeError: Cannot destructure property 'objectProperties' of '(intermediate value)(intermediate value)(intermediate value)' as it is undefined.
如何使用TS修复它?
错误意味着您试图解构一个可能的undefined
(因为您使用可选链接)
你可以做
const { objectProperties, reportProperties, textProperties } = registryReportSettings?.extended ?? {};
所以你总是会解构一个对象