Skip to content

Commit 6941efb

Browse files
refactor: improve type definitions for async/if then
PR-URL: #1381 Closes: #1095 Signed-off-by: Philipp Burckhardt <pburckhardt@outlook.com> Co-authored-by: Philipp Burckhardt <pburckhardt@outlook.com> Reviewed-by: Philipp Burckhardt <pburckhardt@outlook.com>
1 parent 54669d7 commit 6941efb

File tree

1 file changed

+11
-2
lines changed
  • lib/node_modules/@stdlib/utils/async/if-else/docs/types

1 file changed

+11
-2
lines changed

lib/node_modules/@stdlib/utils/async/if-else/docs/types/index.d.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* @param error - encountered error or null
2525
* @param result - `x` or `y`
2626
*/
27-
type Callback = ( error: Error | null, result: any ) => void;
27+
type Callback<T> = ( error: Error | null, result: T ) => void;
2828

2929
/**
3030
* Predicate callback function.
@@ -61,6 +61,15 @@ type PredicateCallback = PredicateNullary | PredicateUnary | PredicateBinary;
6161
*/
6262
type Predicate = ( clbk: PredicateCallback ) => void;
6363

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+
6473
/**
6574
* If a predicate function returns a truthy value, returns `x`; otherwise, returns `y`.
6675
*
@@ -87,7 +96,7 @@ type Predicate = ( clbk: PredicateCallback ) => void;
8796
* }
8897
* ifelseAsync( predicate, 1.0, -1.0, done );
8998
*/
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;
91100

92101

93102
// EXPORTS //

0 commit comments

Comments
 (0)