Closed sf-twingate closed 3 months ago
Visit the deploys page to approve it
Name | Link |
---|---|
Latest commit | 24660b8e1cb77282c262a6cacc16518ee8294b87 |
Latest commit: 24660b8e1cb77282c262a6cacc16518ee8294b87
The changes in this PR will be included in the next version bump.
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
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 >=3.10.5
a try and report back?
I believe this was already solved with #11848 so we'll go ahead and close this. Thanks for the contribution!
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:
```tsx import { FetchResult, GraphQLRequest, gql } from "@apollo/client"; // The `ResultFunction`, `VariableMatcher` & `MockedResponse` types below are the current types // defined in `mockLink.ts`. type ResultFunctionProposed 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:
```tsx import { FetchResult, GraphQLRequest, gql } from "@apollo/client"; // The `ResultFunction` & `VariableMatcher` types below have been updated to declare their own generics. type ResultFunctionI'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!