diff --git a/packages/mobx-state-tree/__tests__/core/async.test.ts b/packages/mobx-state-tree/__tests__/core/async.test.ts index b9d154031..a3e0f5448 100644 --- a/packages/mobx-state-tree/__tests__/core/async.test.ts +++ b/packages/mobx-state-tree/__tests__/core/async.test.ts @@ -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(time: number, value: TV, shouldThrow = false): Promise { return new Promise((resolve, reject) => { @@ -27,7 +27,7 @@ function testCoffeeTodo( done: () => void, generator: ( self: any - ) => (str: string) => Generator, string | void | undefined, undefined>, + ) => (str: string) => Generator, string | void | undefined, undefined>, shouldError: boolean, resultValue: string | undefined, producedCoffees: any[] diff --git a/packages/mobx-state-tree/src/core/flow.ts b/packages/mobx-state-tree/src/core/flow.ts index 8e8609a96..b194a953f 100644 --- a/packages/mobx-state-tree/src/core/flow.ts +++ b/packages/mobx-state-tree/src/core/flow.ts @@ -1,3 +1,4 @@ +import { argsToArray, fail, setImmediateWithFallback } from "../utils" import { getCurrentActionContext, getNextActionId, @@ -5,12 +6,11 @@ import { IMiddlewareEventType, runWithActionContext } from "./action" -import { argsToArray, setImmediateWithFallback, fail } from "../utils" /** * @hidden */ -export type FlowReturn = R extends Promise ? T : R +export type FlowReturn = R extends PromiseLike ? T : R /** * See [asynchronous actions](concepts/async-actions.md). @@ -18,8 +18,8 @@ export type FlowReturn = R extends Promise ? T : R * @returns The flow as a promise. */ export function flow( - generator: (...args: Args) => Generator, R, any> -): (...args: Args) => Promise> { + generator: (...args: Args) => Generator, R, any> +): (...args: Args) => PromiseLike> { return createFlowSpawner(generator.name, generator) as any } @@ -56,7 +56,7 @@ export function castFlowReturn(val: T): T { * })) * ``` */ -export function toGeneratorFunction(p: (...args: Args) => Promise) { +export function toGeneratorFunction(p: (...args: Args) => PromiseLike) { return function* (...args: Args) { return (yield p(...args)) as R }