Over-eager inference with ThisType & homomorphic mapped types #18805
Labels
Needs Proposal
This issue needs a plan that clarifies the finer details of how it could be implemented.
Suggestion
An idea for TypeScript
@ahejlsberg and I have spoken about this a few times offline, but @bterlson was asking if we had an issue tracking this problem.
We've been working with Vue's API to try to give users a better experience. Unfortunately, this is still a very easy gotcha to fall into.
As a boiled down case, try running the following example with
noImplicitAny
andnoImplicitThis
:Here, you'll get a problem on
bar
and on thex
inthis.x
, you'll get:The problem surfaces as soon as any value on
this
is used in producing the return value of a computed method.I forget exactly why this occurs, but it has to do with circularities in trying to draw inferences to
C
which is wrapped in a homomorphic mapped type. @ahejlsberg can fill me in here.The solution for users is to add a return type annotation to
bar
which is not obvious, but it prevents type argument inference from type-checking the internals of the method, and avoids the circularity problem. Ideally, users should not have to think about this.The text was updated successfully, but these errors were encountered: