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
Expected behavior:
No errors; the m method in the subclass has exactly the same signature as the method it is overriding.
Actual behavior:
The compiler warns on the method override B.m:
Type '<T, U extends T>(t: T, u: U) => void' is not assignable
to type '<T, U extends T>(t: T, u: U) => void'.
Two different types with this name exist, but they are unrelated.
Types of parameters 'u' and 'u' are incompatible.
Type 'U' is not assignable to type 'T'.
Type 'T' is not assignable to type 'T'.
Two different types with this name exist, but they are unrelated.
Note that even if you change the names of the type parameters in method B.m, as in:
classBextendsA{m<T2,U2extendsT2>(t: T2,u: U2){}}
you still get the error Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated.
If you remove the extends T generic constraint, it compiles.
Related Issues:
Nothing obviously related; #23960 maybe?
So, is this a compiler bug? Or is it intended, and if so, what's the reasoning for it? This issue is inspired by a Stack Overflow question that left me scratching my head.
The text was updated successfully, but these errors were encountered:
@RyanCavanaugh Any plan to fix this issue ? There might be a workaround using ts-ignore feature, but the ts-ignore comment is not ported over declaration files
TypeScript Version: 3.0.0-dev.20180630
Search Terms: generic method, subclass, override, type parameter constraint
Code
Expected behavior:
No errors; the
m
method in the subclass has exactly the same signature as the method it is overriding.Actual behavior:
The compiler warns on the method override
B.m
:Note that even if you change the names of the type parameters in method
B.m
, as in:you still get the error
Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated.
If you remove the
extends T
generic constraint, it compiles.Playground Link:
here
Related Issues:
Nothing obviously related; #23960 maybe?
So, is this a compiler bug? Or is it intended, and if so, what's the reasoning for it? This issue is inspired by a Stack Overflow question that left me scratching my head.
The text was updated successfully, but these errors were encountered: