Skip to content

Commit d4f4b47

Browse files
committed
Updated typings (#819)
1 parent cfd4e70 commit d4f4b47

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

index.d.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ import Transport, {
2727
TransportRequestParams,
2828
TransportRequestOptions,
2929
nodeFilterFn,
30-
nodeSelectorFn
30+
nodeSelectorFn,
31+
TransportRequestCallback
3132
} from './lib/Transport';
3233
import Connection, { AgentOptions, agentFn } from './lib/Connection';
3334
import ConnectionPool, { ResurrectEvent } from './lib/ConnectionPool';
@@ -38,12 +39,18 @@ import * as errors from './lib/errors';
3839
declare type anyObject = {
3940
[key: string]: any;
4041
};
41-
declare type callbackFn = (err: Error | null, result: ApiResponse) => void;
4242

43-
interface ApiMethod<T> {
44-
(callback?: callbackFn): any;
45-
(params: T, callback?: callbackFn): any;
46-
(params: T, options: TransportRequestOptions, callback?: callbackFn): any;
43+
declare type callbackFn<T> = (err: Error | null, result: ApiResponse<T>) => void;
44+
45+
interface ApiMethod<TParams, TBody = any> {
46+
// Promise API
47+
(): Promise<ApiResponse<TBody>>;
48+
(params: TParams): Promise<ApiResponse<TBody>>;
49+
(params: TParams, options: TransportRequestOptions): Promise<ApiResponse<TBody>>;
50+
// Callback API
51+
(callback: callbackFn<TBody>): TransportRequestCallback;
52+
(params: TParams, callback: callbackFn<TBody>): TransportRequestCallback;
53+
(params: TParams, options: TransportRequestOptions, callback: callbackFn<TBody>): TransportRequestCallback;
4754
}
4855

4956
// Extend API
@@ -570,5 +577,6 @@ export {
570577
RequestEvent,
571578
ResurrectEvent,
572579
RequestParams,
580+
ClientOptions,
573581
ClientExtendsCallbackOptions
574582
};

lib/Transport.d.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ export interface TransportRequestOptions {
9696
warnings?: [string];
9797
}
9898

99+
export interface TransportRequestCallback {
100+
abort: () => void;
101+
}
102+
99103
export default class Transport {
100104
static sniffReasons: {
101105
SNIFF_ON_START: string;
@@ -117,7 +121,8 @@ export default class Transport {
117121
_nextSniff: number;
118122
_isSniffing: boolean;
119123
constructor(opts: TransportOptions);
120-
request(params: TransportRequestParams, options: TransportRequestOptions, callback: (err: Error | null, result: ApiResponse) => void): any;
124+
request(params: TransportRequestParams, options?: TransportRequestOptions): Promise<ApiResponse>;
125+
request(params: TransportRequestParams, options?: TransportRequestOptions, callback?: (err: Error | null, result: ApiResponse) => void): TransportRequestCallback;
121126
getConnection(): Connection | null;
122127
sniff(callback?: (...args: any[]) => void): void;
123128
}

0 commit comments

Comments
 (0)