Skip to content
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

Is the typing on MutationUpdaterFn correct? #8506

Closed
dphrag opened this issue Jul 16, 2021 · 2 comments
Closed

Is the typing on MutationUpdaterFn correct? #8506

dphrag opened this issue Jul 16, 2021 · 2 comments

Comments

@dphrag
Copy link

dphrag commented Jul 16, 2021

In node_modules\@apollo\client\core\watchQueryOptions.d.ts the MutationUpdaterFn is defined as

export declare type MutationUpdaterFn<T = { [key: string]: any; }> = (cache: ApolloCache<T>, mutationResult: FetchResult<T>) => void;

The generic T type gets passed into ApolloCache, however this cache object doesn't have anything to do with the fetch result. To me this looks wrong, and ends up describing parts of the ApolloCache incorrectly.

@benjamn
Copy link
Member

benjamn commented Jul 16, 2021

@dphrag You're right about this! We've rewritten these types in the upcoming Apollo Client v3.4 release (see #7902), and the MutationUpdaterFunction type now looks like this:

export type MutationUpdaterFunction<
  TData,
  TVariables,
  TContext,
  TCache extends ApolloCache<any>
> = (
  cache: TCache,
  result: Omit<FetchResult<TData>, 'context'>,
  options: {
    context?: TContext,
    variables?: TVariables,
  },
) => void;

If you have a chance, try updating with npm i @apollo/client@beta. We're in the Release Candidate phase of testing, so the prerelease versions should be pretty stable at this point.

@dphrag
Copy link
Author

dphrag commented Jul 16, 2021

Thanks!! I was worried I had gone mad, typing can be confusing :P

@dphrag dphrag closed this as completed Jul 16, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants