elbywan / wretch

A tiny wrapper built around fetch with an intuitive syntax. :candy:
MIT License
4.83k stars 98 forks source link

Options typings missing #251

Closed codeit-ninja closed 1 month ago

codeit-ninja commented 1 month ago

The type for options is object

wretch.options

var factory.options: (options: object, replace?: boolean) => void

wretch

wretch(_url?: string, _options?: {}): Wretch

I had a quik look in the code, and appearently WretchOptions in is not defined either, its just Record<string, any>. Since I have little time I asked ChatGPT if he knew what all available types were.

Without veryifing it myself it gave me this:

type WretchOptions = {
    baseUrl?: string;                     // Base URL for requests
    headers?: Record<string, string>;     // Default headers for requests
    credentials?: 'omit' | 'same-origin' | 'include';  // CORS credentials mode
    mode?: 'cors' | 'no-cors' | 'same-origin'; // Request mode
    redirect?: 'follow' | 'error' | 'manual';  // Redirect behavior
    timeout?: number;                     // Timeout for requests in milliseconds
    signal?: AbortSignal;                 // AbortSignal to cancel requests
    retry?: {
        limit?: number;                   // Maximum number of retry attempts
        delay?: number;                   // Delay between retries in milliseconds
    } | number;                            // Can also be just a number for retry limit
    throwOnError?: boolean;               // Whether to throw on HTTP errors
    body?: string | object | FormData | URLSearchParams | ReadableStream; // Default body
    type?: 'application/json' | 'application/x-www-form-urlencoded' | 'multipart/form-data'; // Content type
};
elbywan commented 1 month ago

Hey @codeit-ninja,

Yes the options argument is loosely typed on purpose to be able to pass various properties depending on the underlying fetch implementation (or to store arbitrary data).