Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Setting responseType in options results in TS2769: No overload matches this call #1079

Closed
2 tasks done
jgehrcke opened this issue Feb 19, 2020 · 2 comments
Closed
2 tasks done

Comments

@jgehrcke
Copy link

I seem to be able to use many of the documented options parameters just fine, but when I set responseType then compilation fails.

Environment

  • Node.js version: v12.16.1
  • OS & version: Linux
npm run tsc -- --version
...
Version 3.7.5

got version 10.5.7
@types/got version 9.6.9

Repro

cat got_repro.ts:

import got from "got";

async function main() {
  const options = {
    responseType: "buffer"
  };

  const response = await got("http://127.0.0.1/api", options);
  console.log(response);
}

main()
  .then(console.log)
  .catch(console.error);

results in ...

npm run tsc -- got_repro.ts

got_repro.ts:8:54 - error TS2769: No overload matches this call.
  The last overload gave the following error.
    Argument of type '{ responseType: string; }' is not assignable to parameter of type 'Merge<Merge<RequestOptions, Merge<GotOptions, URLOptions>>, { isStream: true; }>'.
      Type '{ responseType: string; }' is not assignable to type 'Pick<Merge<RequestOptions, Merge<GotOptions, URLOptions>>, "search" | "host" | "password" | "origin" | "body" | "form" | ... 64 more ... | "servername">'.
        Types of property 'responseType' are incompatible.
          Type 'string' is not assignable to type 'ResponseType'.

8   const response = await got("http://127.0.0.1/api", options);
                                                       ~~~~~~~

  node_modules/got/dist/source/create.d.ts:48:5
     48     <T>(url: string | Merge<Options, {
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     49         isStream: true;
        ~~~~~~~~~~~~~~~~~~~~~~~
    ... 
     51         isStream: true;
        ~~~~~~~~~~~~~~~~~~~~~~~
     52     }>): ProxyStream<T>;
        ~~~~~~~~~~~~~~~~~~~~~~~~
    The last overload is declared here.


Found 1 error.

The documentation says that this parameter

can be 'text', 'json' or 'buffer'.

I have tried these values. The only way to make my compiler happy is to not set responseType in options.

Any help is appreciated.

Checklist

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

Just for the record I have uninstalled the old @types/got and get the same error.

@szmarczak
Copy link
Collaborator

Duplicate of #954

@szmarczak szmarczak marked this as a duplicate of #954 Feb 19, 2020
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants