以下代码块运行正常,但会引发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; }'.