Skip to content
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

Error TS since update to 14.4.1 : responseType does not exists on type "OptionsOfUnknownResponseBody" #2357

Closed
2 tasks done
throrin19 opened this issue Jun 10, 2024 · 5 comments

Comments

@throrin19
Copy link

throrin19 commented Jun 10, 2024

Describe the bug

  • Node.js version: 20.14.0
  • OS & version: macOs 13.6.7

Actual behavior

After update to got 14.4.1 I have several errors in got usage when I pass the property responseType. This is an error TS2353 said responseType does not exists on type "OptionsOfUnknownResponseBody" :

image

After research, the problems is due to modifications introduced by #2353.

Expected behavior

All works fine, same as oldest versions

Code to reproduce

await got('-/reload', {
        method: 'POST',
        prefixUrl: promServer,
        responseType: 'json',
        retry: {
            limit: 0,
        },
    });

Checklist

  • I have read the documentation.
  • I have tried my code with the latest version of Node.js and Got.
@sindresorhus
Copy link
Owner

// @spence-s

@spence-s
Copy link
Contributor

spence-s commented Jun 10, 2024

I tried reproducing but it works fine for me and correctly resolves to the OptionsOfJSONResponseBody (using node 20):

Screenshot 2024-06-10 at 9 38 56 AM

After you updated the package did you run tsc to prove the error exists or are you only noticing it in your editor? If it's only in editor, then try restarting the editor.

What version of typescript are you using? It's possible that an older version may not resolve correctly.

@throrin19
Copy link
Author

throrin19 commented Jun 10, 2024

@spence-s I'm in typescript 5.4.5 but it's my bad. I create a proxy function to capture and format errors with more readable logic for us (retrieve body and simplify error) :

/**
 * Wrapper to got library
 *
 * @param uri - URI to request
 * @param options - Got options
 * @returns Request's response
 */
export const got = async (uri: string | URL, options?: OptionsOfUnknownResponseBody) => {
    try {
        return await originGot(uri, options);
    } catch (err) {
        throw new GotError(err as RequestError);
    }
};

But i made a mistake in it. How to retrieve a type with all available options to replace OptionsOfUnknownResponseBody ?

@spence-s
Copy link
Contributor

spence-s commented Jun 10, 2024

How to retrieve a type with all available options to replace OptionsOfUnknownResponseBody ?

Oh I see 😄 . You should change it to OptionsOfJSONResponseBody now or optionally you OptionsOfUnknownResponseBody | OptionsOfJSONResponseBody should work I believe.

Let me know if that works for your use case now. I need to go back and update the types documentation a bit.

@throrin19
Copy link
Author

Thanks, it works fine. Sorry for this ticket 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants