Skip to content

Commit

Permalink
feat(#8): Extend overload support
Browse files Browse the repository at this point in the history
  • Loading branch information
iainjreid committed May 22, 2024
1 parent c7a1b56 commit 0ed5f98
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ A strongly typed drop-in replacement for Promises in TypeScript.
## Installation

Promise is available from the NPM registry and as a GitHub Package. Whichever
source you prefer to use, the installation instructions should remain the same.
source you prefer to use, the installation should remain the same.

```sh
# Using NPM
Expand Down
8 changes: 7 additions & 1 deletion lib/promise.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ declare type AssertRejects<T extends Promise<any, U>, U extends RejectType<V>, V
* Upgrade a vanilla Promise to a strongly typed Promise while respecting
* function overloads.
*
* Support is provided for functions with four or fewer arguments.
* Support is provided for functions with six or fewer overloads.
*
* @remarks
*
Expand All @@ -99,6 +99,12 @@ declare type AssertRejects<T extends Promise<any, U>, U extends RejectType<V>, V
* {@link https://stackoverflow.com/a/64330561/4000053}
*/
type UpgradePromise<T, E = unknown> =
T extends
{ (...args: infer A1): PromiseLike<infer R1>; (...args: infer A2): PromiseLike<infer R2>; (...args: infer A3): PromiseLike<infer R3>; (...args: infer A4): PromiseLike<infer R4>; (...args: infer A5): PromiseLike<infer R5>; (...args: infer A6): PromiseLike<infer R6>; } ?
{ (...args: A1): Promise<R1, E>; (...args: A2): Promise<R2, E>; (...args: A3): Promise<R3, E>; (...args: A4): Promise<R4, E>; (...args: A5): Promise<R5, E>; (...args: A6): Promise<R6, E>; } :
T extends
{ (...args: infer A1): PromiseLike<infer R1>; (...args: infer A2): PromiseLike<infer R2>; (...args: infer A3): PromiseLike<infer R3>; (...args: infer A4): PromiseLike<infer R4>; (...args: infer A5): PromiseLike<infer R5>; } ?
{ (...args: A1): Promise<R1, E>; (...args: A2): Promise<R2, E>; (...args: A3): Promise<R3, E>; (...args: A4): Promise<R4, E>; (...args: A5): Promise<R5, E>; } :
T extends
{ (...args: infer A1): PromiseLike<infer R1>; (...args: infer A2): PromiseLike<infer R2>; (...args: infer A3): PromiseLike<infer R3>; (...args: infer A4): PromiseLike<infer R4>; } ?
{ (...args: A1): Promise<R1, E>; (...args: A2): Promise<R2, E>; (...args: A3): Promise<R3, E>; (...args: A4): Promise<R4, E>; } :
Expand Down

0 comments on commit 0ed5f98

Please sign in to comment.