Repo: Investigate better handling of unconstrained generics #10438
Labels
accepting prs
Go ahead, send a pull request that resolves this issue
locked due to age
Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.
repo maintenance
things to do with maintenance of the repo, and not with code/docs
Suggestion
Sadly, right now
getConstrainedTypeOfLocation
is bugged for unconstrained generics. The code just gives back the type parameter type if getBaseConstraintOfType(nodeType) is nullish, but that's not correct. Unconstrained generics should behave likeunknown
. Here's what it is right now:typescript-eslint/packages/type-utils/src/getConstrainedTypeAtLocation.ts
Lines 7 to 20 in 62d5755
And here's what it "should" be:
Unfortunately, due to microsoft/TypeScript#60475, there is no
checker.getUnknownType()
yet or for a while.It kind of sucks, but I propose that we instead modify the implementation to something more like
and force callers to handle the unconstrained case separately.
Note - I think we should also double-check (and add tests) for what happens when the constraint is
any
. I'm pretty surefunction f<T extends any>(x: T) {}
behaves as thoughT
wereunknown
rather thanany
. So maybe we should really be doingI haven't yet checked what
checker.getBaseConstraintOfType()
does with anany
.Additional Info
Related, caused #10311
Related, discussion at #10314 (comment)
Possibly related, #10415
cc @ronami
The text was updated successfully, but these errors were encountered: