-
-
Notifications
You must be signed in to change notification settings - Fork 613
Closed
Labels
PRs welcomePRs are welcome to solve this issue!PRs are welcome to solve this issue!enhancementNew feature or requestNew feature or requestopenapi-fetchRelevant to the openapi-fetch libraryRelevant to the openapi-fetch libraryquestionFurther information is requestedFurther information is requested
Description
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
Labels
PRs welcomePRs are welcome to solve this issue!PRs are welcome to solve this issue!enhancementNew feature or requestNew feature or requestopenapi-fetchRelevant to the openapi-fetch libraryRelevant to the openapi-fetch libraryquestionFurther information is requestedFurther information is requested