-
Notifications
You must be signed in to change notification settings - Fork 116
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
Can access to typed data in interceptors #380
Comments
It would be great to type the response data!
AFAIK the only way to type chainable functions array is to specify finite number of function overloads, how RxJS does it with |
Maybe we can consider separating the different context types based on situation, for example: interface FetchOptions<
R extends ResponseType = ResponseType,
T = any,
> extends Omit<RequestInit, "body"> {
// ...
onRequestError?(
context: Pick<FetchContext, 'options' | 'request'> & {
response: undefined;
error: Error;
}
): Promise<void> | void;
onResponse?(
context: Pick<FetchContext, 'options' | 'request'> & {
response: MappedResponseType<R, T>;
error: undefined;
}
): Promise<void> | void;
// ...
}
ofetch<{ id: string; }>("api", {
onRequestError({ response, error }) {
// the error type will be Error
// the response type will be undefined
},
onResponse({ response, error }) {
// the error type will be undefined
// the response type will be "{ id: string; }"
},
}) |
Describe the feature
This feature request aims to enhance the usability of interceptors by allowing seamless access to typed data within the interceptor functions.
Expected usage:
Additional information
The text was updated successfully, but these errors were encountered: