Auto Type narrowing for array union type when the first element type is determined #49185
Closed
5 tasks done
Labels
Duplicate
An existing issue was already created
Suggestion
π Search Terms
is:issue union type array guard first element
β Viability Checklist
My suggestion meets these guidelines:
β Suggestion
If we have a union type array like
declare const array: string[] | number[]
, and the first element type is determined in a branch, we should be able to narrow the array type tostring[]
ornumber[]
.(Of course we can now use custom type guards for our purposes, but it would be exciting if this were all automated.)
π Motivating Example
playground
π» Use Cases
Save time writing custom type guards, and code reading experience will be better
The text was updated successfully, but these errors were encountered: