orval
orval copied to clipboard
Customizing error type (TError) in SWR integration
I'm using orval with SWR, and it's working fine, but the error type is always unknown unless I provide them at the usage level each time I want to use an API call. It's a good idea to type the error somehow in the customInstance or in orval.config.js. Is it possible?
Hey @movahedan, you can export an ErrorType type in the mutator which should do the job. You have an example here
@anymaniax customInstance is only receiving one generic argument, which is the response. Is there any way to adapt customInstance to support two generic arguments and leave orval do the rest? Like:
export const getUsers = (options?: SecondParameter<typeof customInstance>) => {
return customInstance<Users, UsersError>({ url: `/api/users`, method: 'get' }, options);
};
By having this, we would avoid casting all the derived created react query hooks (for example).
Hey @movahedan, you can export an ErrorType type in the mutator which should do the job. You have an example here
Yes, that's exactly what I did previously in my project. Seems a bit tricky though. I agree with @vitorcamachoo, that would be even nicer.
@movahedan
Hi, have all your questions about this issue been resolved? Is there anything I can do to help?
@melloware
Hi, I will watch this issue, so could you assign it to me? Or, since it seems like the question has already been resolved, you may want to close it.
I will close it for now as it seems like it was answered.