Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

Commit

Permalink
introduce native promise support incl. documentation & types
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyler Miller committed Aug 6, 2021
1 parent 0e14594 commit 106da62
Show file tree
Hide file tree
Showing 5 changed files with 325 additions and 255 deletions.
14 changes: 13 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,19 @@
"version": "1.7.0",
"description": "Comprehensive NodeJS API wrapper for the Robinhood API",
"main": "src/robinhood.js",
"typings": "robinhood.d.ts",
"typings": "types/robinhood.d.ts",
"typesVersions": {
"<4.1": {
"promises": [
"types/promises.v3.d.ts"
]
},
">=4.1": {
"promises": [
"types/promises.d.ts"
]
}
},
"exports": {
".": "./src/robinhood.js",
"./promises": "./src/promises.js",
Expand Down
254 changes: 0 additions & 254 deletions robinhood.d.ts

This file was deleted.

42 changes: 42 additions & 0 deletions types/promises.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// requires typescript 4.1+

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;

declare function 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;
15 changes: 15 additions & 0 deletions types/promises.v3.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// for typescript <4.1

import robinhood = require("./robinhood");

declare function RobinhoodPromiseAPI(
options: robinhood.Options.WebApiOpts
): Promise<
{
[key in keyof robinhood.RobinhoodWebApi]: (
...args: any[]
) => Promise<any>;
}
>;

export = RobinhoodPromiseAPI;
Loading

0 comments on commit 106da62

Please sign in to comment.