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
FooType<number> fully resolves to number[] | number, and BarType<number> fully resolves to number | number[] | (number | number[])[]. There is no self reference or circular reference here.
Because of CFA, when you assign const bar: BarType<number> = [], the actual type of bar is narrowed to number[] | (number | number[])[], so that you can call .push on it. Also note that function parameter type is contravariance, that means (M[] | N[]).push will only accept M & N. In your case it is number & (number | number[]), which resolves to number.
Bug Report
π Search Terms
union generics
self-referential generic
ndarray
recursive type references
π Version & Regression Information
β― Playground Link
Playground Link
π» Code
π Actual behavior
When making use of an indirect self-referential union generic such as:
I'm unable to assign what I believe to be a reasonable pathway of the expansion
this should be the equivalent of
FooType<number>[]
, however typescript disagrees that this assignment is validand only allows type
number
Argument of type 'number[]' is not assignable to parameter of type 'number'.
I understand that the message is due to the number literal, but the typing is equivalent, as expressed
by the annotations.
Interestingly the single type version of this works, as demonstrated in (#33050)
So it appears that the indirection is what's breaking this.
π Expected behavior
I'm able to compile the above without error
The text was updated successfully, but these errors were encountered: