为什么扩展得到时我不能使用类型作为responseType选项?

时间:2020-03-16 13:06:33

标签: typescript

以下代码块运行正常,但会引发TypeScript错误。

got的类型定义非常古怪。我做错了什么还是应该提交错误报告?

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
  }))
}
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; }'.

0 个答案:

没有答案
相关问题