init hook types
#2127
-
How can I add types to the https://github.com/sindresorhus/got/blob/main/documentation/9-hooks.md#init import got from 'got';
const instance = got.extend({
hooks: {
init: [
(plain, options) => {
if ('secret' in plain) {
options.context.secret = plain.secret;
delete plain.secret;
}
}
],
beforeRequest: [
options => {
options.headers.secret = options.context.secret;
}
]
}
});
const {headers} = await instance(
'https://httpbin.org/anything',
{
// TS error: 'secret' does not exist in type 'OptionsInit'
secret: 'passphrase'
}
).json();
console.log(headers.Secret); |
Beta Was this translation helpful? Give feedback.
Answered by
szmarczak
Aug 31, 2022
Replies: 1 comment
-
Duplicate of #1117 |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
aphilas
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Duplicate of #1117