-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MockLink: update the function types returned by ResultFunction
& VariableMatcher
to define their own generics
#11812
base: main
Are you sure you want to change the base?
Conversation
👷 Deploy request for apollo-client-docs pending review.Visit the deploys page to approve it
|
🦋 Changeset detectedLatest commit: 24660b8 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
0d7ca97
to
1717cb5
Compare
ResultFunction
& VariableMatcher
to define their own genericsResultFunction
& VariableMatcher
to define their own generics
ResultFunction
& VariableMatcher
to define their own genericsResultFunction
& VariableMatcher
to define their own generics
… `VariableMatcher`
6c67aa9
to
4053fb7
Compare
c18b72a
to
442f7f6
Compare
442f7f6
to
24660b8
Compare
Hey @sf-twingate 👋 We'll do our best to get to this PR soon. Thanks so much for the contribution! |
I believe this might have been solved in a different way in #11848, could you please give a version |
Issue
A feature introduced last year (#6701) which updated
MockLink
'sResultFunction
type and introduced a newVariableMatcher
type (both referenced byMockedResponse
) has caused a type issue our repository that is affecting our team's common practice of setting a generic whichextends
fromMockedResponse[]
on our test setup functions (e.g.function setup<M extends MockedResponse[]>
).This issue arises due to both types accepting a variables generic type (
V
), and then returning a function type which uses this generic as its own argument type:When these types are combined with our usage of
M extends MockedResponse[]
, TypeScript is unable to correctly infer thevariables
argument type for each of of the values inM
.Example Failure
Here's an isolated example of this which will currently fail type checking:
Failing Example:
Proposed Fix
I believe this can be fixed, without causing any breaking changes, by making the function types returned by
ResultFunction
&VariableMatcher
declare their own generic type, which extends from and defaults to theV
type.This resolves the issue in the snippet above:
Example Fix:
I've implemented the change as part of this PR and added a test case which currently fails when run against
main
, but passes on this branch.Please let me know if you have any questions / concerns about the changes — thanks!