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
Constrained generic class property has any type after instanceofΒ #60810
Your MyClass<string> | unknown confused me for a minute into thinking you were asking for something else (i.e., that MyClass<X> | unknown should be narrowed to MyClass<X> if you use instanceof, but that's not possible because unknown absorbs everything). Maybe you can just change it to unknown, since that's the same thing and there's no implication of narrowing to a union member?
Is the idea that since MyClass<T> is covariant in T, that the constraint should be used instead of any when narrowing via instanceof? And if it were contravariant you'd expect never, and if it were invariant or otherwise problematic then any would be fine?
Activity
jcalz commentedon Dec 18, 2024
Your
MyClass<string> | unknownconfused me for a minute into thinking you were asking for something else (i.e., thatMyClass<X> | unknownshould be narrowed toMyClass<X>if you useinstanceof, but that's not possible becauseunknownabsorbs everything). Maybe you can just change it tounknown, since that's the same thing and there's no implication of narrowing to a union member?Is the idea that since
MyClass<T>is covariant inT, that the constraint should be used instead ofanywhen narrowing viainstanceof? And if it were contravariant you'd expectnever, and if it were invariant or otherwise problematic thenanywould be fine?MartinJohns commentedon Dec 18, 2024
Duplicate of #17473.