Description
Example use case: A middleware that adds a configurable timeout, like this: #2527 (comment)
// Timeout middleware
fetchClient.use({
async onRequest({ request, params: { timeout } }) {
const signal =
timeout === Infinity ?
request.signal
: AbortSignal.any([
request.signal,
AbortSignal.timeout(typeof timeout === 'number' && timeout >= 0 ? timeout : REQUEST_TIMEOUT),
]);
return new Request(request, { signal });
},
});
Since #2527, the MiddlewareRequestParams are easily augmentable:
declare module 'openapi-fetch' {
interface MiddlewareRequestParams {
timeout?: number;
}
}
so maybe, ParamsOption should somehow do the same.
Proposal
Ergonomically, I'd like to send my request like this
client['/api/takes-a-while'].PUT({ params: { timeout: 120_000 } })
and use the timeout custom param in my middleware, without type assertions or disabling TypeScript for this line.
Alternatively, I could also imagine a custom meta option, like TanStack Query does it: https://tanstack.com/query/latest/docs/framework/react/typescript#typing-meta
client['/api/takes-a-while'].PUT({ meta: { timeout: 120_000 } })
and accessing it from the middleware like this:
// Timeout middleware
fetchClient.use({
async onRequest({ request, meta: { timeout } }) {
// ...
Extra
Description
Example use case: A middleware that adds a configurable timeout, like this: #2527 (comment)
Since #2527, the
MiddlewareRequestParamsare easily augmentable:so maybe,
ParamsOptionshould somehow do the same.Proposal
Ergonomically, I'd like to send my request like this
and use the
timeoutcustom param in my middleware, without type assertions or disabling TypeScript for this line.Alternatively, I could also imagine a custom
metaoption, like TanStack Query does it: https://tanstack.com/query/latest/docs/framework/react/typescript#typing-metaand accessing it from the middleware like this:
Extra