ThisType would disturb Generics' inferring type when assign an expression to a type variable #39848
Labels
Needs Investigation
This issue needs a team member to investigate its status.
Milestone
TypeScript Version: 3.9.2, and it does exist in 'Nightly' version, too.
Search Terms: ThisType, Generics, Inferring problem
Code
Expected behavior:
We expect
ReturnedD = D extends customFunc ? ReturnType<D> : never
infersReturnedD
toReturnType<D>
at runtime sinceD
fits the shape ofcustomFunc
:And the code should show no error in TypeScript environment.
Actual behavior:
The actual behavior is that
ReturnedD
is inferred tonever
type sinceD extends customFunc
here is false at runtime.You can also check it with the returned type of
instance
as well.Playground Link:
Check out the link here.
Personal speculation:
If you look at the demo above, you can do following steps to remove the error hint and confirm
ReturnedD
's correction:ReturnedD
fromThisType<M & ReturnedD & CC>
;this.firstname
, etc;instance
inferred from TypeScript is as expected and would not benever
;I also reproduced it with TypeScript playground.
We can confirm that:
ReturnedD
runs well in inferring type at runtime;ThisType
;The text was updated successfully, but these errors were encountered: