UNPKG

@dreamkit/solid

Version:

DreamKit tools for Solid.

47 lines 1.68 kB
import { TryPick } from "@dreamkit/utils/ts.js"; export type ActionState = "idle" | "running" | "success" | "error"; export type StatedActionResult<T extends (...args: any[]) => any> = { readonly state: "idle"; readonly running: false; readonly args: undefined; readonly result: undefined; readonly error: undefined; } | { readonly state: "running"; readonly running: true; readonly args: Parameters<T>; readonly result: undefined; readonly error: undefined; } | { readonly state: "success"; readonly running: false; readonly args: Parameters<T>; readonly result: Awaited<ReturnType<T>>; readonly error: undefined; } | { readonly state: "error"; readonly running: false; readonly args: Parameters<T>; readonly result: undefined; readonly error: Error; }; type IsAny<T> = 0 extends 1 & T ? true : false; export type ActionResult<T extends (...args: any[]) => any, SourceT extends (...args: any[]) => any = T> = { (...args: Parameters<T>): void; with: { (input: () => IsAny<T> extends true ? any : Parameters<T>[0]): ActionResult<() => ReturnType<T>, SourceT>; (...args: Parameters<T>): ActionResult<() => ReturnType<T>, SourceT>; }; readonly id: number; readonly isErrorUsed: boolean; readonly canRetry: boolean; clear: () => void; abort: () => void; retry: () => void; ref: { readonly errorWithoutUsing: Error; }; } & TryPick<SourceT, "title" | "params"> & StatedActionResult<T>; export declare function createAction<T extends (...args: any[]) => any>(cb: T): ActionResult<T>; export {}; //# sourceMappingURL=createAction.d.ts.map