This repository has been archived by the owner on Nov 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Tyler Miller
committed
Aug 5, 2021
1 parent
0e14594
commit 95f95d4
Showing
5 changed files
with
327 additions
and
255 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// drawback: requires typescript 4.1+ | ||
// drawback: Parameters<> doesn't preserve parameter/tuple labels, | ||
// and probably not jsdoc annotations either | ||
|
||
import robinhood = require("./robinhood"); | ||
|
||
type RemoveFnParam<T extends unknown[]> = T extends [] | ||
? [] | ||
: T extends [infer H, ...infer R] | ||
? H extends Function | ||
? RemoveFnParam<R> | ||
: [H, ...RemoveFnParam<R>] | ||
: T; | ||
|
||
type LastTupleElement<T extends unknown[]> = T extends [infer X] | ||
? X | ||
: T extends [infer H, ...infer R] | ||
? LastTupleElement<R> | ||
: T; | ||
|
||
type RobinhoodPromiseAPI = ( | ||
options: robinhood.Options.WebApiOpts | ||
) => Promise< | ||
{ | ||
[key in keyof robinhood.RobinhoodWebApi]: ( | ||
...args: RemoveFnParam<Parameters<robinhood.RobinhoodWebApi[key]>> | ||
) => Promise< | ||
LastTupleElement< | ||
Parameters<robinhood.RobinhoodWebApi[key]> | ||
> extends Function | ||
? LastTupleElement< | ||
Parameters< | ||
// @ts-expect-error: this must be a function in this block | ||
LastTupleElement< | ||
Parameters<robinhood.RobinhoodWebApi[key]> | ||
> | ||
> | ||
> | ||
: ReturnType<robinhood.RobinhoodWebApi[key]> | ||
>; | ||
} | ||
>; | ||
|
||
export = RobinhoodPromiseAPI; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// for older typescripts | ||
|
||
import robinhood = require("./robinhood"); | ||
|
||
type RobinhoodPromiseAPI = ( | ||
options: robinhood.Options.WebApiOpts | ||
) => Promise< | ||
{ | ||
[key in keyof robinhood.RobinhoodWebApi]: ( | ||
...args: any[] | ||
) => Promise<any>; | ||
} | ||
>; | ||
|
||
export = RobinhoodPromiseAPI; |
Oops, something went wrong.