You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Code
Nested optional property existence check via !! vs. Boolean()
// strictNullChecks: trueinterfaceAddress{country: string;}interfaceStudent{address?: Address;}conststudent: Student={address: {country: 'US',}};// this one works just fine, no error reportedconstb1: boolean=student&&!!student.address&&student.address.country==='US';// this one reports an error for the second student.address: Object is possibly 'undefined' // whereas !!something should be the same as Boolean(something)constb2: boolean=student&&Boolean(student.address)&&student.address.country==='US';
Expected behavior:
"Object is possibly 'undefined' error" should not be reported when accessing student.address after the existence of address on student is verified.
Actual behavior:
"Object is possibly 'undefined' error" is reported when student.address is accessed the second time after its existence is already verified.
The text was updated successfully, but these errors were encountered:
TypeScript Version: 2.0.3
Code
Nested optional property existence check via !! vs. Boolean()
Expected behavior:
"Object is possibly 'undefined' error" should not be reported when accessing student.address after the existence of address on student is verified.
Actual behavior:
"Object is possibly 'undefined' error" is reported when student.address is accessed the second time after its existence is already verified.
The text was updated successfully, but these errors were encountered: