diff --git a/src/task.ts b/src/task.ts index d696891..29948e7 100644 --- a/src/task.ts +++ b/src/task.ts @@ -1,11 +1,6 @@ import { observable, action } from 'mobx' import { proxyGetters, promiseTry } from './utils' -/** - * Returns a type without the promise wrapper. - */ -export type WithoutPromise = T extends Promise ? P : T - /** * Task status. */ @@ -22,7 +17,7 @@ export type TaskFunc = (...args: A) => Promise export interface TaskOptions { state?: TaskStatus error?: unknown - result?: WithoutPromise + result?: Awaited args?: A swallow?: boolean } @@ -33,7 +28,7 @@ export interface TaskOptions { export interface TaskMatchProps { pending?: (...args: A) => T1 rejected?: (error: unknown) => T2 - resolved?: (result: WithoutPromise) => T3 + resolved?: (result: Awaited) => T3 } /** @@ -63,7 +58,7 @@ export interface TaskState { /** * The result of the last invocation. */ - readonly result?: WithoutPromise + readonly result?: Awaited /** * The error of the last failed invocation. */ @@ -101,7 +96,7 @@ export interface TaskMethods { /** * Task function, state and methods. */ -export type Task = TaskFunc> & +export type Task = TaskFunc> & TaskState & TaskMethods @@ -184,7 +179,7 @@ function createTask( ;(task as Task).setState({ state: 'resolved', error: undefined, - result: result as WithoutPromise, + result: result as Awaited, }) } return result