Skip to content

Openapi-fetch with promise-like interface #1226

@andrius-kurtinaitis

Description

@andrius-kurtinaitis

Description

When calling REST client functions, I expect to get Resolved with data when it was a success, and Reject with an error in case of failure.

Proposal

I'm trying to wrap for openapi-fetch like this:

export const { get, put, post, del } = createClient<paths>({ baseUrl: '/api' });

export const putClient = (url: Parameters<typeof put>[0], init: Parameters<typeof put>[1]) =>
  put(url, init)
    .catch((error: Error) => // network error - no response
      Promise.reject(errorToString(error)))
    .then(({ data, error, response }) =>
      data ?? Promise.reject(problemToString(response, error)));

But I can't get the types right. Apparently url: Parameters<typeof put>[0], init: Parameters<typeof put>[1] does not do the trick and wrong operations are getting picked from the generated ts file.
Any suggestions?

Metadata

Metadata

Assignees

No one assigned

    Labels

    PRs welcomePRs are welcome to solve this issue!enhancementNew feature or requestopenapi-fetchRelevant to the openapi-fetch libraryquestionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions