Skip to content

Commit

Permalink
Merge pull request #55 from skychik/patch-1
Browse files Browse the repository at this point in the history
fix: use Awaited instead of WithoutPromise
  • Loading branch information
jeffijoe committed Feb 2, 2024
2 parents e6c64ee + 5169bb0 commit 7c88d92
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions 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> = T extends Promise<infer P> ? P : T

/**
* Task status.
*/
Expand All @@ -22,7 +17,7 @@ export type TaskFunc<A extends any[], R> = (...args: A) => Promise<R>
export interface TaskOptions<A extends any[], R> {
state?: TaskStatus
error?: unknown
result?: WithoutPromise<R>
result?: Awaited<R>
args?: A
swallow?: boolean
}
Expand All @@ -33,7 +28,7 @@ export interface TaskOptions<A extends any[], R> {
export interface TaskMatchProps<T1, T2, T3, A extends any[], R = any> {
pending?: (...args: A) => T1
rejected?: (error: unknown) => T2
resolved?: (result: WithoutPromise<R>) => T3
resolved?: (result: Awaited<R>) => T3
}

/**
Expand Down Expand Up @@ -63,7 +58,7 @@ export interface TaskState<A extends any[], R> {
/**
* The result of the last invocation.
*/
readonly result?: WithoutPromise<R>
readonly result?: Awaited<R>
/**
* The error of the last failed invocation.
*/
Expand Down Expand Up @@ -101,7 +96,7 @@ export interface TaskMethods<A extends any[], R> {
/**
* Task function, state and methods.
*/
export type Task<A extends any[], R> = TaskFunc<A, WithoutPromise<R>> &
export type Task<A extends any[], R> = TaskFunc<A, Awaited<R>> &
TaskState<A, R> &
TaskMethods<A, R>

Expand Down Expand Up @@ -184,7 +179,7 @@ function createTask<A extends any[], R>(
;(task as Task<A, R>).setState({
state: 'resolved',
error: undefined,
result: result as WithoutPromise<R>,
result: result as Awaited<R>,
})
}
return result
Expand Down

0 comments on commit 7c88d92

Please sign in to comment.