我有这段代码,我检查 hostel.country.address 是否为空,但仍然如此
return hostel.country.address &&
hostel.country.address.internalEmployeeIdentifier !== null ||
hostel.country.address.externalEmployeeIdentifier !== null;
我遇到这个编译问题
hostel.country.address
Object is possibly 'null' or 'undefined'.
- error TS2533: Object is possibly 'null' or 'undefined'.
最佳答案
return hostel.country.address &&
hostel.country.address!.internalEmployeeIdentifier !== null ||
hostel.country.address!.externalEmployeeIdentifier !== null;
应该可以。
祝你好运
关于javascript - 检查对象可能是 'null' 或 'undefined',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59731407/