Type not narrowed when putting optional1 || optional2
condition in if
statement and repeating it in its body
#52210
Closed
5 tasks done
Labels
Duplicate
An existing issue was already created
Suggestion
π Search Terms
β Viability Checklist
My suggestion meets these guidelines:
β Suggestion
This code (playground link):
produces this type error on the
return required(a || b)
line:but TypeScript should be able to infer that
a || b
can only be anumber
notnumber | undefined
because the||
expression must be true in theif
block.π Motivating Example
I am checking two optional properties of an object and using them interchangeably. Currently I have to use an
as
expression.π» Use Cases
See above.
The text was updated successfully, but these errors were encountered: