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

Can’t use type with responseType option #1122

Closed
2 tasks done
sunknudsen opened this issue Mar 16, 2020 · 3 comments
Closed
2 tasks done

Can’t use type with responseType option #1122

sunknudsen opened this issue Mar 16, 2020 · 3 comments

Comments

@sunknudsen
Copy link

Describe the bug

  • Node.js version: v12.14.1
  • OS & version: macOS Mojave 10.14.6

Actual behavior

I believe this issue is a TypeScript type declaration bug.

I am building on top of got and having issues with the responseType option.

Expected behavior

The following code block should not throw type error.

Code to reproduce

import got from "got"

export type ResponseType = "text" | "json" | "buffer"

const send = async function(responseType: ResponseType) {
  console.log(await got({
    url: "https://api.example.net",
    method: "GET",
    responseType: responseType
  }))
}

Checklist

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

What is the type error?

@sunknudsen
Copy link
Author

@sindresorhus

The last overload gave the following error.
  Argument of type '{ method: Method; url: string; searchParams: string; json: { [key: string]: any; }; headers: Headers; responseType: ResponseType; hooks: { beforeRequest: (() => Promise<void>)[]; beforeRetry: ((options: NormalizedOptions, error: GeneralError, retryCount: number) => Promise<...>)[]; }; }' is not assignable to parameter of type 'string | Merge<Merge<RequestOptions, Merge<GotOptions, URLOptions>>, { isStream: true; }>'.
    Type '{ method: Method; url: string; searchParams: string; json: { [key: string]: any; }; headers: Headers; responseType: ResponseType; hooks: { beforeRequest: (() => Promise<void>)[]; beforeRetry: ((options: NormalizedOptions, error: GeneralError, retryCount: number) => Promise<...>)[]; }; }' is not assignable to type 'Merge<Merge<RequestOptions, Merge<GotOptions, URLOptions>>, { isStream: true; }>'.
      Property 'isStream' is missing in type '{ method: Method; url: string; searchParams: string; json: { [key: string]: any; }; headers: Headers; responseType: ResponseType; hooks: { beforeRequest: (() => Promise<void>)[]; beforeRetry: ((options: NormalizedOptions, error: GeneralError, retryCount: number) => Promise<...>)[]; }; }' but required in type '{ isStream: true; }'.

@szmarczak
Copy link
Collaborator

Possibly a duplicate of #954

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