24
24
* @param error - encountered error or null
25
25
* @param result - `x` or `y`
26
26
*/
27
- type Callback = ( error : Error | null , result : any ) => void ;
27
+ type Callback < T > = ( error : Error | null , result : T ) => void ;
28
28
29
29
/**
30
30
* Predicate callback function.
@@ -61,6 +61,15 @@ type PredicateCallback = PredicateNullary | PredicateUnary | PredicateBinary;
61
61
*/
62
62
type Predicate = ( clbk : PredicateCallback ) => void ;
63
63
64
+ /**
65
+ * Determines the relationship between two types `T` and `U`, and returns:
66
+ *
67
+ * - `T` if `T` is assignable to `U`,
68
+ * - `U` if `U` is assignable to `T`,
69
+ * - A union of `U | T` as a fallback.
70
+ */
71
+ type ResultFunction < T , U > = T extends U ? T : U extends T ? U : U | T ;
72
+
64
73
/**
65
74
* If a predicate function returns a truthy value, returns `x`; otherwise, returns `y`.
66
75
*
@@ -87,7 +96,7 @@ type Predicate = ( clbk: PredicateCallback ) => void;
87
96
* }
88
97
* ifelseAsync( predicate, 1.0, -1.0, done );
89
98
*/
90
- declare function ifelseAsync ( predicate : Predicate , x : any , y : any , done : Callback ) : void ;
99
+ declare function ifelseAsync < T , U = T > ( predicate : Predicate , x : T , y : U , done : Callback < ResultFunction < T , U > > ) : void ;
91
100
92
101
93
102
// EXPORTS //
0 commit comments