curl返回值类型缩小
LasyIsLazy opened this issue · comments
Enter your suggestions in details:
遇到的问题:
项目使用的EggJS从V2升级到了V3,遇到一些代码报错:
const response = await ctx.curl('xxx', { data });
response.res.statusMessage;
抛错:
Property 'statusMessage' does not exist on type '(IncomingMessage & { timing?: { queuing: number; dnslookup: number; connected: number; requestSent: number; waiting: number; contentDownload: number; } | undefined; }) | RawResponseWithMeta'.
Property 'statusMessage' does not exist on type 'RawResponseWithMeta'.
当前 curl API 返回值的类型是 Promise<HttpClientResponseOld<T> | HttpClientResponse<T>>
,
运行时具体返回的值看起来应该是取决于 config.httpclient.useHttpClientNext
是否开启。
Lines 294 to 305 in 9957b9c
对我当前的项目来说,我没有使用 useHttpClientNext
,所以实际返回值一直都是 HttpClientResponseOld
,但我确实不能直接使用这个类型上和 HttpClientResponse
不兼容的属性,还是有些困惑的。
目前还没找到相关的文档。
statusMessage 丢失了,这个可以加上兼容。https://github.com/node-modules/urllib 的 bug