-
Notifications
You must be signed in to change notification settings - Fork 12.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type predicates and narrowing Arrays #50359
Labels
Duplicate
An existing issue was already created
Comments
This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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: