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
Currently, it is not possible to narrow down the type of a union of arrays based on the types of their contents, even if the arrays of the union are disjunct. I suggest updating the typechecker, if possible, to allow for this.
π Motivating Example
If we try to do it the naive way, we get the following scenario:
This is not ideal, as it makes for needlessly verbose code. There's also no simple way to implement a type predicate to do this generically over any array of any type.
The ideal scenario would be for the first example to infer the desired types.
π» Use Cases
This makes for cleaner code and a more streamlined and intuitive user experience. The current approach makes for clunky and bloated code when dealing with arrays, as the only way to properly type things is with type assertions.
The text was updated successfully, but these errors were encountered:
Suggestion
π Search Terms
type
narrowing
array
β Viability Checklist
My suggestion meets these guidelines:
β Suggestion
Currently, it is not possible to narrow down the type of a union of arrays based on the types of their contents, even if the arrays of the union are disjunct. I suggest updating the typechecker, if possible, to allow for this.
π Motivating Example
If we try to do it the naive way, we get the following scenario:
Instead, the programmer is forced to write a type assertion on top of verifying the type of the array
This is not ideal, as it makes for needlessly verbose code. There's also no simple way to implement a type predicate to do this generically over any array of any type.
The ideal scenario would be for the first example to infer the desired types.
π» Use Cases
This makes for cleaner code and a more streamlined and intuitive user experience. The current approach makes for clunky and bloated code when dealing with arrays, as the only way to properly type things is with type assertions.
The text was updated successfully, but these errors were encountered: