From b7f89aac252d504f0b3a0f8255006c085c6f3dc9 Mon Sep 17 00:00:00 2001 From: Aron Carroll Date: Mon, 15 Mar 2021 21:51:17 +0000 Subject: [PATCH] refactor: Fix request type definition We now distinguish between the callback variant and the promise --- src/lib/request/index.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/lib/request/index.ts b/src/lib/request/index.ts index 4cc8ce97bf..21bc132dda 100644 --- a/src/lib/request/index.ts +++ b/src/lib/request/index.ts @@ -4,10 +4,17 @@ import { MetricsCollector } from '../metrics'; import * as needle from 'needle'; // A hybrid async function: both returns a promise and takes a callback -export = async ( +async function requestWrapper( + payload: any, +): Promise<{ res: needle.NeedleResponse; body: any }>; +async function requestWrapper( + payload: any, + callback: (err: Error | null, res?, body?) => void, +): Promise; +async function requestWrapper( payload: any, callback?: (err: Error | null, res?, body?) => void, -): Promise => { +): Promise { const totalNetworkTimeTimer = MetricsCollector.NETWORK_TIME.createInstance(); totalNetworkTimeTimer.start(); try { @@ -28,4 +35,6 @@ export = async ( } finally { totalNetworkTimeTimer.stop(); } -}; +} + +export = requestWrapper;