-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
recursive/nested types for arrays #28929
Comments
Consider the following snippet: type Nest = number | Array<Nest>;
type Okay = number | { nest: Okay }; Today, the type
The type The current rationale is explained in #12525:
(emphasis mine) The current restrictions apply to all type aliases (e.g. I think a reasonable minimal change to support the above use case would be to add two additional cycle-breakers: The general case of cycle-breaking in type aliases can be addressed later. |
Right - type aliases can't be directly recursive because in trying to resolve them, the type-checker would try to eat its own tail and spin off. See more on Wikipedia: https://en.wikipedia.org/w/index.php?title=Recursive_data_type&oldid=812740950#In_type_synonyms
|
We don't need the general case to be handled for this bug to be resolved. Is there any reason that |
Here's a real use case: implementing Right now, |
Fixed in #33050. |
So I had this:
for a certain situation it was actually insufficient and the compiler required me to do this:
I can't figure out why the compiler forced me to do that, the above seems like a bug. Since the second operand in the union type seems like it would have covered it. Am I right or wrong?
Anyway, what I am ultimately looking for is a recursive type for arrays, like so:
https://stackoverflow.com/questions/53646270/declare-arbitrarily-nested-array-recursive-type-definition
The text was updated successfully, but these errors were encountered: