Skip to content

Commit

Permalink
fix(types): Switching Promise to PromiseLike (#1850 by @kav)
Browse files Browse the repository at this point in the history
  • Loading branch information
kav authored Feb 4, 2022
1 parent f297ae2 commit 89b977d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
16 changes: 8 additions & 8 deletions packages/mobx-state-tree/__tests__/core/async.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { configure, reaction } from "mobx"
import {
types,
addMiddleware,
recordActions,
flow,
decorate,
destroy,
IMiddlewareHandler,
flow,
IMiddlewareEvent,
IMiddlewareEventType,
toGeneratorFunction,
toGenerator
IMiddlewareHandler,
recordActions,
toGenerator,
// TODO: export IRawActionCall
toGeneratorFunction,
types
} from "../../src"
import { reaction, configure } from "mobx"

function delay<TV>(time: number, value: TV, shouldThrow = false): Promise<TV> {
return new Promise((resolve, reject) => {
Expand All @@ -27,7 +27,7 @@ function testCoffeeTodo(
done: () => void,
generator: (
self: any
) => (str: string) => Generator<Promise<any>, string | void | undefined, undefined>,
) => (str: string) => Generator<PromiseLike<any>, string | void | undefined, undefined>,
shouldError: boolean,
resultValue: string | undefined,
producedCoffees: any[]
Expand Down
10 changes: 5 additions & 5 deletions packages/mobx-state-tree/src/core/flow.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import { argsToArray, fail, setImmediateWithFallback } from "../utils"
import {
getCurrentActionContext,
getNextActionId,
getParentActionContext,
IMiddlewareEventType,
runWithActionContext
} from "./action"
import { argsToArray, setImmediateWithFallback, fail } from "../utils"

/**
* @hidden
*/
export type FlowReturn<R> = R extends Promise<infer T> ? T : R
export type FlowReturn<R> = R extends PromiseLike<infer T> ? T : R

/**
* See [asynchronous actions](concepts/async-actions.md).
*
* @returns The flow as a promise.
*/
export function flow<R, Args extends any[]>(
generator: (...args: Args) => Generator<Promise<any>, R, any>
): (...args: Args) => Promise<FlowReturn<R>> {
generator: (...args: Args) => Generator<PromiseLike<any>, R, any>
): (...args: Args) => PromiseLike<FlowReturn<R>> {
return createFlowSpawner(generator.name, generator) as any
}

Expand Down Expand Up @@ -56,7 +56,7 @@ export function castFlowReturn<T>(val: T): T {
* }))
* ```
*/
export function toGeneratorFunction<R, Args extends any[]>(p: (...args: Args) => Promise<R>) {
export function toGeneratorFunction<R, Args extends any[]>(p: (...args: Args) => PromiseLike<R>) {
return function* (...args: Args) {
return (yield p(...args)) as R
}
Expand Down

0 comments on commit 89b977d

Please sign in to comment.