export type Config = { id?: string }; export type Fn = (...args: any[]) => any; export type MethodParameters = [ Func, Config, Parameters, ]; export type Updater = () => void; export type Memoized = { updaters: Set; cleanupTimeout?: ReturnType; //cancel?: ReturnType cancel?: () => void; suspender?: any; value?: [any, AsyncReturnType?]; }; export type UseAsync = AsyncReturnType; export type Recall = Promise; export type UseAsyncSafe = [ null | any, AsyncReturnType?, ]; export type UseAsyncLoadingState = | { isLoading: true; data?: void; } | { isLoading: false; data: AsyncReturnType; }; export type UseAsyncSafeLoadingState = | { isLoading: true; data: void; error: void; } | { isLoading: false; data?: AsyncReturnType; error: any; }; export type MethodReturnType< Method, Func extends Fn, > = Method extends "useAsync" ? UseAsync : Method extends "recall" ? Recall : Method extends "useAsyncSafe" ? UseAsyncSafe : Method extends "useAsyncLoadingState" ? UseAsyncLoadingState : Method extends "useAsyncSafeLoadingState" ? UseAsyncSafeLoadingState : never; // https://www.jpwilliams.dev/how-to-unpack-the-return-type-of-a-promise-in-typescript export type AsyncReturnType any> = T extends ( ...args: any ) => Promise ? U : T extends (...args: any) => infer U ? U : any;