Skip to content

Commit c8dfeab

Browse files
author
Habib
committed
Improve flow typing
1 parent 16f8586 commit c8dfeab

1 file changed

Lines changed: 5 additions & 28 deletions

File tree

src/api/flow.ts

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,9 @@ export interface FlowIterator<T> {
1010
throw?(e?: any): IteratorResult<T> | Promise<IteratorResult<T>>
1111
}
1212

13-
export function flow<R>(generator: () => FlowIterator<any>): () => CancellablePromise<R>
14-
export function flow<A1>(
15-
generator: (a1: A1) => FlowIterator<any>
16-
): (a1: A1) => CancellablePromise<any> // Ideally we want to have R instead of Any, but cannot specify R without specifying A1 etc... 'any' as result is better then not specifying request args
17-
export function flow<A1, A2>(
18-
generator: (a1: A1, a2: A2) => FlowIterator<any>
19-
): (a1: A1, a2: A2) => CancellablePromise<any>
20-
export function flow<A1, A2, A3>(
21-
generator: (a1: A1, a2: A2, a3: A3) => FlowIterator<any>
22-
): (a1: A1, a2: A2, a3: A3) => CancellablePromise<any>
23-
export function flow<A1, A2, A3, A4>(
24-
generator: (a1: A1, a2: A2, a3: A3, a4: A4) => FlowIterator<any>
25-
): (a1: A1, a2: A2, a3: A3, a4: A4) => CancellablePromise<any>
26-
export function flow<A1, A2, A3, A4, A5>(
27-
generator: (a1: A1, a2: A2, a3: A3, a4: A4, a5: A5) => FlowIterator<any>
28-
): (a1: A1, a2: A2, a3: A3, a4: A4, a5: A5) => CancellablePromise<any>
29-
export function flow<A1, A2, A3, A4, A5, A6>(
30-
generator: (a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6) => FlowIterator<any>
31-
): (a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6) => CancellablePromise<any>
32-
export function flow<A1, A2, A3, A4, A5, A6, A7>(
33-
generator: (a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6, a7: A7) => FlowIterator<any>
34-
): (a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6, a7: A7) => CancellablePromise<any>
35-
export function flow<A1, A2, A3, A4, A5, A6, A7, A8>(
36-
generator: (a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6, a7: A7, a8: A8) => FlowIterator<any>
37-
): (a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6, a7: A7, a8: A8) => CancellablePromise<any>
38-
export function flow(generator: Function) {
13+
export function flow<T, U extends any[]>(
14+
generator: (...args: U) => FlowIterator<any>
15+
): (...args: U) => CancellablePromise<T> {
3916
if (arguments.length !== 1)
4017
fail(process.env.NODE_ENV && `Flow expects one 1 argument and cannot be used as decorator`)
4118
const name = generator.name || "<unnamed flow>"
@@ -49,7 +26,7 @@ export function flow(generator: Function) {
4926
let rejector: (error: any) => void
5027
let pendingPromise: CancellablePromise<any> | undefined = undefined
5128

52-
const res = new Promise(function(resolve, reject) {
29+
const res = new Promise<T>(function(resolve, reject) {
5330
let stepId = 0
5431
rejector = reject
5532

@@ -111,7 +88,7 @@ export function flow(generator: Function) {
11188
rejector(e) // there could be a throwing finally block
11289
}
11390
})
114-
return res
91+
return res as CancellablePromise<T>
11592
}
11693
}
11794

0 commit comments

Comments
 (0)