From d4f4b47d7e278033ac0dd257ab5ada0f3b594385 Mon Sep 17 00:00:00 2001 From: Tomas Della Vedova Date: Wed, 17 Apr 2019 11:23:15 +0200 Subject: [PATCH] Updated typings (#819) --- index.d.ts | 20 ++++++++++++++------ lib/Transport.d.ts | 7 ++++++- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/index.d.ts b/index.d.ts index 3154eec37..328243995 100644 --- a/index.d.ts +++ b/index.d.ts @@ -27,7 +27,8 @@ import Transport, { TransportRequestParams, TransportRequestOptions, nodeFilterFn, - nodeSelectorFn + nodeSelectorFn, + TransportRequestCallback } from './lib/Transport'; import Connection, { AgentOptions, agentFn } from './lib/Connection'; import ConnectionPool, { ResurrectEvent } from './lib/ConnectionPool'; @@ -38,12 +39,18 @@ import * as errors from './lib/errors'; declare type anyObject = { [key: string]: any; }; -declare type callbackFn = (err: Error | null, result: ApiResponse) => void; -interface ApiMethod { - (callback?: callbackFn): any; - (params: T, callback?: callbackFn): any; - (params: T, options: TransportRequestOptions, callback?: callbackFn): any; +declare type callbackFn = (err: Error | null, result: ApiResponse) => void; + +interface ApiMethod { + // Promise API + (): Promise>; + (params: TParams): Promise>; + (params: TParams, options: TransportRequestOptions): Promise>; + // Callback API + (callback: callbackFn): TransportRequestCallback; + (params: TParams, callback: callbackFn): TransportRequestCallback; + (params: TParams, options: TransportRequestOptions, callback: callbackFn): TransportRequestCallback; } // Extend API @@ -570,5 +577,6 @@ export { RequestEvent, ResurrectEvent, RequestParams, + ClientOptions, ClientExtendsCallbackOptions }; diff --git a/lib/Transport.d.ts b/lib/Transport.d.ts index 3a349cbf1..989d02c76 100644 --- a/lib/Transport.d.ts +++ b/lib/Transport.d.ts @@ -96,6 +96,10 @@ export interface TransportRequestOptions { warnings?: [string]; } +export interface TransportRequestCallback { + abort: () => void; +} + export default class Transport { static sniffReasons: { SNIFF_ON_START: string; @@ -117,7 +121,8 @@ export default class Transport { _nextSniff: number; _isSniffing: boolean; constructor(opts: TransportOptions); - request(params: TransportRequestParams, options: TransportRequestOptions, callback: (err: Error | null, result: ApiResponse) => void): any; + request(params: TransportRequestParams, options?: TransportRequestOptions): Promise; + request(params: TransportRequestParams, options?: TransportRequestOptions, callback?: (err: Error | null, result: ApiResponse) => void): TransportRequestCallback; getConnection(): Connection | null; sniff(callback?: (...args: any[]) => void): void; }