UNPKG

1.98 kBTypeScriptView Raw
1/**
2 * @hidden
3 */
4export declare type FlowReturn<R> = R extends Promise<infer T> ? T : R;
5/**
6 * See [asynchronous actions](concepts/async-actions.md).
7 *
8 * @returns The flow as a promise.
9 */
10export declare function flow<R, Args extends any[]>(generator: (...args: Args) => Generator<Promise<any>, R, any>): (...args: Args) => Promise<FlowReturn<R>>;
11/**
12 * @deprecated Not needed since TS3.6.
13 * Used for TypeScript to make flows that return a promise return the actual promise result.
14 *
15 * @param val
16 * @returns
17 */
18export declare function castFlowReturn<T>(val: T): T;
19/**
20 * @experimental
21 * experimental api - might change on minor/patch releases
22 *
23 * Convert a promise-returning function to a generator-returning one.
24 * This is intended to allow for usage of `yield*` in async actions to
25 * retain the promise return type.
26 *
27 * Example:
28 * ```ts
29 * function getDataAsync(input: string): Promise<number> { ... }
30 * const getDataGen = toGeneratorFunction(getDataAsync);
31 *
32 * const someModel.actions(self => ({
33 * someAction: flow(function*() {
34 * // value is typed as number
35 * const value = yield* getDataGen("input value");
36 * ...
37 * })
38 * }))
39 * ```
40 */
41export declare function toGeneratorFunction<R, Args extends any[]>(p: (...args: Args) => Promise<R>): (...args: Args) => Generator<Promise<R>, R, R>;
42/**
43 * @experimental
44 * experimental api - might change on minor/patch releases
45 *
46 * Convert a promise to a generator yielding that promise
47 * This is intended to allow for usage of `yield*` in async actions to
48 * retain the promise return type.
49 *
50 * Example:
51 * ```ts
52 * function getDataAsync(input: string): Promise<number> { ... }
53 *
54 * const someModel.actions(self => ({
55 * someAction: flow(function*() {
56 * // value is typed as number
57 * const value = yield* toGenerator(getDataAsync("input value"));
58 * ...
59 * })
60 * }))
61 * ```
62 */
63export declare function toGenerator<R>(p: Promise<R>): Generator<Promise<R>, R, R>;