From 5d1bd2231ee565c20c8d48fd3fcaa95baefdd090 Mon Sep 17 00:00:00 2001 From: Julian Hundeloh Date: Mon, 17 Jun 2019 09:01:33 +0200 Subject: [PATCH] (got) fix: add init hook (#36145) * fix: add init hook * test: add test * test: separate test case * fix: set return value to void * fix: update version --- types/got/got-tests.ts | 9 +++++++++ types/got/index.d.ts | 8 +++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/types/got/got-tests.ts b/types/got/got-tests.ts index 9bb1b75d81..4f6ff5f464 100644 --- a/types/got/got-tests.ts +++ b/types/got/got-tests.ts @@ -341,6 +341,15 @@ got('http://todomvc.com', { got('http://todomvc.com', { timeout: 1 }).catch((err) => err instanceof got.TimeoutError); // Test hooks. +got('example.com', { + hooks: { + init: [ + options => { + options.baseUrl = 'https://google.com'; + } + ] + } +}); got('example.com', { hooks: { beforeRequest: [ diff --git a/types/got/index.d.ts b/types/got/index.d.ts index 20909101ca..86e566f48b 100644 --- a/types/got/index.d.ts +++ b/types/got/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for got 9.4 +// Type definitions for got 9.6 // Project: https://github.com/sindresorhus/got#readme // Definitions by: BendingBender // Linus Unnebäck @@ -140,12 +140,18 @@ declare namespace got { * @template Body Response body type. */ interface Hooks { + init?: Array>; beforeRequest?: Array>; beforeRedirect?: Array>; beforeRetry?: Array>; afterResponse?: Array>; } + /** + * @param options Unnormalized request options. + */ + type InitHook = (options: Options) => void; + /** * @param options Normalized request options. */