Closed
Labels
DuplicateAn existing issue was already createdAn existing issue was already created
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
Metadata
Metadata
Assignees
Labels
DuplicateAn existing issue was already createdAn existing issue was already created
Activity
IllusionMH commentedon Apr 3, 2020
Duplicate of #16655
Unfortunately changing
Booleandeclaration breaks cases withfilteretc.See #29955
typescript-bot commentedon Apr 5, 2020
This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.