From 32449249e48c33f334e4f52bba462ade662c6d77 Mon Sep 17 00:00:00 2001 From: Prajwal Kulkarni Date: Sun, 25 Feb 2024 05:19:18 +0000 Subject: [PATCH 1/3] refactor: improve type definitions for async/if then --- .../@stdlib/utils/async/if-else/docs/types/index.d.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/utils/async/if-else/docs/types/index.d.ts b/lib/node_modules/@stdlib/utils/async/if-else/docs/types/index.d.ts index 7dd425b4092c..8ff764a0d5ff 100644 --- a/lib/node_modules/@stdlib/utils/async/if-else/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/utils/async/if-else/docs/types/index.d.ts @@ -24,7 +24,7 @@ * @param error - encountered error or null * @param result - `x` or `y` */ -type Callback = ( error: Error | null, result: any ) => void; +type Callback = ( error: Error | null, result: T ) => void; /** * Predicate callback function. @@ -61,6 +61,7 @@ type PredicateCallback = PredicateNullary | PredicateUnary | PredicateBinary; */ type Predicate = ( clbk: PredicateCallback ) => void; +type ResultFunction = T extends U ? T : U; /** * If a predicate function returns a truthy value, returns `x`; otherwise, returns `y`. * @@ -87,7 +88,7 @@ type Predicate = ( clbk: PredicateCallback ) => void; * } * ifelseAsync( predicate, 1.0, -1.0, done ); */ -declare function ifelseAsync( predicate: Predicate, x: any, y: any, done: Callback ): void; +declare function ifelseAsync( predicate: Predicate, x: T, y: U, done: Callback> ): void; // EXPORTS // From ed211ea4e0436a83893879ea0c9d863507c31a89 Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Sun, 25 Feb 2024 15:33:18 -0500 Subject: [PATCH 2/3] Apply suggestions from code review Signed-off-by: Philipp Burckhardt --- .../utils/async/if-else/docs/types/index.d.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/utils/async/if-else/docs/types/index.d.ts b/lib/node_modules/@stdlib/utils/async/if-else/docs/types/index.d.ts index 8ff764a0d5ff..d7033bbf829a 100644 --- a/lib/node_modules/@stdlib/utils/async/if-else/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/utils/async/if-else/docs/types/index.d.ts @@ -61,7 +61,15 @@ type PredicateCallback = PredicateNullary | PredicateUnary | PredicateBinary; */ type Predicate = ( clbk: PredicateCallback ) => void; -type ResultFunction = T extends U ? T : U; +/** + * Determines the relationship between two types `T` and `U`, and returns: + * + * - `T` if `T` is assignable to `U`, + * - `U` if `U` is assignable to `T`, + * - A union of `U | T` as a fallback. + */ +type ResultFunction = T extends U ? T : U extends T ? U : U | T; + /** * If a predicate function returns a truthy value, returns `x`; otherwise, returns `y`. * @@ -88,7 +96,7 @@ type ResultFunction = T extends U ? T : U; * } * ifelseAsync( predicate, 1.0, -1.0, done ); */ -declare function ifelseAsync( predicate: Predicate, x: T, y: U, done: Callback> ): void; +declare function ifelseAsync( predicate: Predicate, x: T, y: U, done: Callback> ): void; // EXPORTS // From b0a7823409de379f26719f5ea8f5cf2d5d48e667 Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Sun, 25 Feb 2024 15:33:39 -0500 Subject: [PATCH 3/3] Update lib/node_modules/@stdlib/utils/async/if-else/docs/types/index.d.ts Signed-off-by: Philipp Burckhardt --- .../@stdlib/utils/async/if-else/docs/types/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/utils/async/if-else/docs/types/index.d.ts b/lib/node_modules/@stdlib/utils/async/if-else/docs/types/index.d.ts index d7033bbf829a..7685ccfc8707 100644 --- a/lib/node_modules/@stdlib/utils/async/if-else/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/utils/async/if-else/docs/types/index.d.ts @@ -68,7 +68,7 @@ type Predicate = ( clbk: PredicateCallback ) => void; * - `U` if `U` is assignable to `T`, * - A union of `U | T` as a fallback. */ -type ResultFunction = T extends U ? T : U extends T ? U : U | T; +type ResultFunction = T extends U ? T : U extends T ? U : U | T; /** * If a predicate function returns a truthy value, returns `x`; otherwise, returns `y`.