mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-07-01 15:50:13 +00:00
(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
This commit is contained in:
committed by
Daniel Rosenwasser
parent
1611b14d95
commit
5d1bd2231e
@@ -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: [
|
||||
|
||||
8
types/got/index.d.ts
vendored
8
types/got/index.d.ts
vendored
@@ -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 <https://github.com/BendingBender>
|
||||
// Linus Unnebäck <https://github.com/LinusU>
|
||||
@@ -140,12 +140,18 @@ declare namespace got {
|
||||
* @template Body Response body type.
|
||||
*/
|
||||
interface Hooks<Options, Body extends Buffer | string | object> {
|
||||
init?: Array<InitHook<Options>>;
|
||||
beforeRequest?: Array<BeforeRequestHook<Options>>;
|
||||
beforeRedirect?: Array<BeforeRedirectHook<Options>>;
|
||||
beforeRetry?: Array<BeforeRetryHook<Options>>;
|
||||
afterResponse?: Array<AfterResponseHook<Options, Body>>;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param options Unnormalized request options.
|
||||
*/
|
||||
type InitHook<Options> = (options: Options) => void;
|
||||
|
||||
/**
|
||||
* @param options Normalized request options.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user