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
{{ message }}
Repository navigation
Unable to assign self to indirect self-referential union genericΒ #50283
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.
Activity
whzx5byb commentedon Aug 12, 2022
I don't see any unexpected behavior.
FooType<number>fully resolves tonumber[] | number, andBarType<number>fully resolves tonumber | 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 ofbaris narrowed tonumber[] | (number | number[])[], so that you can call.pushon it. Also note that function parameter type is contravariance, that means(M[] | N[]).pushwill only acceptM & N. In your case it isnumber & (number | number[]), which resolves tonumber.Seamooo commentedon Aug 12, 2022
My mistake, closing