UNPKG

@aspida/swrv

Version:
38 lines 2.02 kB
import { IConfig } from 'swrv'; import { IResponse } from 'swrv/dist/types'; type keyType = string | any[] | null; type AspidaSWRVOption<T> = T & { /** * @deprecated * Will be dropped next major release. * Use key and fetcher options instead. * key: enabled ? undefined : null, * fetcher: enabled ? undefined : null */ enabled?: boolean; key?: keyType | (() => keyType); fetcher?: ((f: (opt: AspidaSWRVOption<T>) => any) => (opt: AspidaSWRVOption<T>) => any) | null | undefined; }; type Options<T extends (option: any) => Promise<any>> = Parameters<Parameters<T> extends [Parameters<T>[0]] ? (option: AspidaSWRVOption<Parameters<T>[0] & Omit<IConfig, 'fetcher'>>) => void : (option?: AspidaSWRVOption<Parameters<T>[0] & Omit<IConfig, 'fetcher'>>) => void>; type Res<T extends (option: any) => Promise<any>> = IResponse<ReturnType<T> extends Promise<infer S> ? S : never, any>; declare function getAspidaSWRVDefaultKey<T extends Record<string, any> & { $get: (option: any) => Promise<any>; $path: (option?: any) => string; }>(api: T, ...option: Options<T['$get']>): string[]; declare function getAspidaSWRVDefaultKey<T extends Record<string, any> & { $path: (option?: any) => string; }, U extends { [K in keyof T]: T[K] extends (option: any) => Promise<any> ? K : never; }[keyof T]>(api: T, method: U, ...option: Options<T[U]>): string[]; export { getAspidaSWRVDefaultKey }; declare function useAspidaSWRV<T extends Record<string, any> & { $get: (option: any) => Promise<any>; $path: (option?: any) => string; }>(api: T | null | (() => T | null), ...option: Options<T['$get']>): Res<T['$get']>; declare function useAspidaSWRV<T extends Record<string, any> & { $path: (option?: any) => string; }, U extends { [K in keyof T]: T[K] extends (option: any) => Promise<any> ? K : never; }[keyof T]>(api: T | null | (() => T | null), method: U, ...option: Options<T[U]>): Res<T[U]>; export default useAspidaSWRV; //# sourceMappingURL=index.d.ts.map