-
-
Notifications
You must be signed in to change notification settings - Fork 938
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to correctly type an instance returned by got.extend
#1117
Comments
For now you need to cast it manually. |
In theory, it can be achieved by conditional types. See examples like sindresorhus/pify#76. @szmarczak If you agree with this kind of mechanism, I can send a PR to handle |
Any news about this? |
I agree that the typing should be correct here, likely by using conditional types as @chinesedfan mentioned. I'd like to point out one workaround for this specific instance of From the docs:
|
I am a newbie in the TS world, I didn't want to type it as |
As workaround I put my response in a const and cast it to any (I guess a custom interface works too), in you case: const jsonClient = got.extend({
responseType: 'json',
resolveBodyOnly: true
});
const response = await jsonClient('https://httpbin.org/json');
const data = response as any;
// other stuffs with data Hope it help! 😃 |
What would you like to discuss?
Given the following client:
Doing:
hints TypeScript to believe that
response
is of typeResponse<string>
while it should beunknown
.How can I correctly type
jsonClient
to take into account my options?Checklist
The text was updated successfully, but these errors were encountered: