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

curl返回值类型缩小 #5300

Closed
LasyIsLazy opened this issue Feb 29, 2024 · 2 comments · Fixed by node-modules/urllib#491
Closed

curl返回值类型缩小 #5300

LasyIsLazy opened this issue Feb 29, 2024 · 2 comments · Fixed by node-modules/urllib#491
Assignees

Comments

@LasyIsLazy
Copy link

LasyIsLazy commented Feb 29, 2024

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 是否开启。

egg/lib/egg.js

Lines 294 to 305 in 9957b9c

get httpclient() {
if (!this[HTTPCLIENT]) {
if (this.config.httpclient.useHttpClientNext) {
this[HTTPCLIENT] = new this.HttpClientNext(this);
} else if (this.config.httpclient.enableDNSCache) {
this[HTTPCLIENT] = new DNSCacheHttpClient(this);
} else {
this[HTTPCLIENT] = new this.HttpClient(this);
}
}
return this[HTTPCLIENT];
}

对我当前的项目来说,我没有使用 useHttpClientNext,所以实际返回值一直都是 HttpClientResponseOld,但我确实不能直接使用这个类型上和 HttpClientResponse 不兼容的属性,还是有些困惑的。

目前还没找到相关的文档。

@fengmk2
Copy link
Member

fengmk2 commented Feb 29, 2024

statusMessage 丢失了,这个可以加上兼容。https://github.com/node-modules/urllib 的 bug

@fengmk2 fengmk2 self-assigned this Feb 29, 2024
@fengmk2
Copy link
Member

fengmk2 commented Feb 29, 2024

node-modules/urllib#306

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants