我有以下内容:
const { var1 } = requestObj1 //requestObj1.var1 = {} => and hence return {}
var1.anotherVariable = reqObj2?.anotherObj?.value //return error: cannot read property of undefined.
requestObj1: { headers: {}, method: 'GET', timeout: 30000, uri: 'some url'
}
我认为我们不能在未定义的对象上使用链接。
您可以指定一个默认值,以便
var1
永远不会未定义:
const { var1={} } = requestObj1
var1.anotherVariable = reqObj2?.anotherObj?.value