@gam-test/fetch-wrapper
Version:
A simple fetch wrapper for better error handling and less response context
13 lines (11 loc) • 745 B
TypeScript
type BodyParser<R> = (response: Response) => Promise<R>;
type ClientConfigWithData<T, R> = Omit<RequestInit, "method" | "body"> & {
throwOnConnectionFailure?: boolean;
bodyParser?: BodyParser<R>;
data: T;
};
type ClientConfigWithDataWithoutBody<T, R> = Omit<ClientConfigWithData<T, R>, "bodyParser">;
type ClientConfig<R> = Omit<ClientConfigWithData<never, R>, "data">;
type ClientConfigWithoutBody<R> = Omit<ClientConfig<R>, "bodyParser">;
type RequestClientConfig<T, R> = ClientConfig<R> | ClientConfigWithoutBody<R> | ClientConfigWithData<T, R> | ClientConfigWithDataWithoutBody<T, R>;
export type { BodyParser, ClientConfig, ClientConfigWithData, ClientConfigWithDataWithoutBody, ClientConfigWithoutBody, RequestClientConfig };