Skip to content

useMutation type constraint error: paths missing index signature (Record<string, Record<HttpMethod, {}>>) #2267

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

Open
1 task
gromchen opened this issue Apr 29, 2025 · 0 comments
Labels
bug Something isn't working openapi-react-query Relevant to openapi-react-query

Comments

@gromchen
Copy link

openapi-react-query version

0.2.5

Description

I’m trying to create a custom helper function to call useMutation without manually retrieving the client from the context each time:

export const useMutation: UseMutationMethod<paths, `${string}/${string}`> = (...args) => {
  const { client } = useClientContext();

  return client.useMutation(...args);
};

However, TypeScript throws the following error:

Type 'paths' does not satisfy the constraint 'Record<string, Record<HttpMethod, {}>>'.
  Index signature for type 'string' is missing in type 'paths'.ts(2344)

Reproduction

I have a client stored inside a React Context because I need access to the auth.js session to provide access tokens in the fetch middleware. The entire application is already wrapped in the client provider. I’m trying to avoid manually calling useClientContext() everywhere — I want a simple, local useMutation hook.

Expected result

One should be able to use the paths type with UseMutationMethod.

Extra

@gromchen gromchen added bug Something isn't working openapi-react-query Relevant to openapi-react-query labels Apr 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working openapi-react-query Relevant to openapi-react-query
Projects
None yet
Development

No branches or pull requests

1 participant