@tonightpass/react
Version:
@tonightpass react sdk.
18 lines (15 loc) • 944 B
TypeScript
import { SWRConfiguration, SWRResponse } from 'swr';
import { Client, PathsFor, TonightPassAPIError, APIRequestOptions, Query, Endpoints } from 'tonightpass';
declare const client: Client;
type AnyEndpoint = Endpoints extends infer T ? T : never;
type ForceAccept<T> = T extends never ? any : T;
type ResponseType<Path extends PathsFor<"GET">> = ForceAccept<Extract<AnyEndpoint, {
path: Path;
method: "GET";
}>["res"]>;
type ErrorType<Path extends PathsFor<"GET">> = TonightPassAPIError<ResponseType<Path>>;
interface UseAPIConfig<Path extends PathsFor<"GET">> extends SWRConfiguration<ResponseType<Path>, ErrorType<Path>> {
requestOptions?: APIRequestOptions;
}
declare function useAPI<Path extends PathsFor<"GET">>(path: Path | null | undefined, query?: Query<Path>, config?: UseAPIConfig<Path>): SWRResponse<ResponseType<Path>, ErrorType<Path>>;
export { type ErrorType, type ResponseType, type UseAPIConfig, client, useAPI };