UNPKG

taro-hooks

Version:
13 lines (12 loc) 671 B
import type { TaroStatic } from '@tarojs/taro'; import type { CallbackResult } from '../type'; export type NonResult<T, R = undefined> = T | R; export type TaroApis = keyof TaroStatic; export type Noop<T = any> = (...args: any[]) => T; export type TaroApiFn<T, U = any, S = Noop> = T extends TaroApis ? TaroStatic[T] extends S ? TaroStatic[T] : S : Noop<U>; /** * a general generate info api hook, make direaction return, use undefined make fail * @param {TCallback<T>} fn * @returns {T} */ export declare function createUseInfoHook<T extends TaroApis, S extends Noop = TaroApiFn<T>, R = Awaited<ReturnType<S>>>(fn: S, defaultReturn?: Partial<R>): CallbackResult<R>;