import * as vue from 'vue'; import { MaybeRefOrGetter, Ref } from 'vue'; type IfAny = 0 extends (1 & T) ? Y : N; /** * will return `true` if `T` is `any`, or `false` otherwise */ type IsAny = IfAny; /** * The source code for this function was inspired by vue-apollo's `useEventHook` util * https://github.com/vuejs/vue-apollo/blob/v4/packages/vue-apollo-composable/src/util/useEventHook.ts */ type Callback = IsAny extends true ? (...param: any) => void : ([ T ] extends [void] ? (...param: unknown[]) => void : (...param: [T, ...unknown[]]) => void); type EventHookOn = (fn: Callback) => { off: () => void; }; type EventHookOff = (fn: Callback) => void; type EventHookTrigger = (...param: IsAny extends true ? unknown[] : [T, ...unknown[]]) => Promise; interface EventHook { on: EventHookOn; off: EventHookOff; trigger: EventHookTrigger; clear: () => void; } type OptionsApiRequest = (...args: any[]) => Promise; interface OptionsApiConfig { /** 请求选项数据源的方法 */ api?: OptionsApiRequest; /** * 请求参数 * - 会传入 `api` 方法 * - 支持传入一个函数, 返回一个对象 * - 当请求参数发生变化时, 会重新发起请求 */ params?: MaybeRefOrGetter | undefined>; /** * 是否立即发起请求 * @default true */ immediate?: boolean; } type OptionsApi = OptionsApiRequest | OptionsApiConfig; interface UseOptionsApiOptions { /** 请求参数 */ params?: MaybeRefOrGetter | undefined>; } declare function useOptionsApi(optionsApi: Ref | undefined>, options?: UseOptionsApiOptions): { propApi: vue.ComputedRef | undefined>; api: { response: T[] | undefined; data: undefined; error: any; isExecuted: boolean; isLoading: boolean; isFinished: boolean; isSuccess: boolean; execute: (...args: any[]) => Promise; reset: () => void; onSuccess: (fn: (param_0: T[] | undefined, ...param: unknown[]) => void) => { off: () => void; }; onError: EventHook["on"]; onFinally: EventHook["on"]; }; loading: vue.ComputedRef; }; export { type OptionsApi, type OptionsApiConfig, type OptionsApiRequest, useOptionsApi };