Closed
Description
TypeScript Version: 3.8.3
Search Terms: Boolean type narrowing
Code
const x: {test: string} | null | undefined = something()
// this works
if (!!x) {
console.log(x.test)
}
// this can not work
if (Boolean(x)) {
console.log(x.test)
}
Expected behavior:
Expression inside the second if statement should work.
Actual behavior:
The second if statement gives the following error:
TS2533: Object is possibly 'null' or 'undefined'.
Related Issues: None