Skip to content

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

Open
@gromchen

Description

@gromchen

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingopenapi-react-queryRelevant to openapi-react-query

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions