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
The invocation of new Test infers generic parameters of <C, C>, even though this.b is B and c is C, which should pretty clearly result in <B, C>. This incorrect inference causes an error on return since it does not match the return type annotation:
Type 'Test<C, C>' is not assignable to type 'Test<B, C>'.
Type 'C' is not assignable to type 'B'.
'B' could be instantiated with an arbitrary type which could be unrelated to 'C'.(2322)
Explicitly invoking new Test<B, C> compiles without error.
π Expected behavior
Compiles successfully.
Additional information about the issue
I initially posted this with a slightly more complex example, where the second argument to both Testβs constructor and the test method was a callback, (v: A) => B and (v: B) => C, respectively. I realized that this callback was a bit of a red herring and the bug occurs even when these are simple, explicitly-annotated values.
The text was updated successfully, but these errors were encountered:
krryan
changed the title
Class infers wrong generic parameter in latest (regression?)
Class infers wrong generic parameter since e1874f3
Apr 4, 2024
π Search Terms
"infer"
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play?ts=5.5.0-dev.20240404#code/KYDwDg9gTgLgBAYwDYEMDOa4BVhpgHgEEAaOAIQD44BvAKDgcQgDs8oBXBGaOACjHYAjJAEsEcFAC44JOAOFi4g6WQCUNAL616jGLgIBhCrwTSDq6Tjz4ypIzR2NGUYDHZRmcZsADu2fbwwABYiaAB0gqQIqgDcjnBaWkA
π» Code
π Actual behavior
The invocation of
new Test
infers generic parameters of<C, C>
, even thoughthis.b
isB
andc
isC
, which should pretty clearly result in<B, C>
. This incorrect inference causes an error onreturn
since it does not match the return type annotation:Explicitly invoking
new Test<B, C>
compiles without error.π Expected behavior
Compiles successfully.
Additional information about the issue
I initially posted this with a slightly more complex example, where the second argument to both
Test
βsconstructor
and thetest
method was a callback,(v: A) => B
and(v: B) => C
, respectively. I realized that this callback was a bit of a red herring and the bug occurs even when these are simple, explicitly-annotated values.The text was updated successfully, but these errors were encountered: