-
Notifications
You must be signed in to change notification settings - Fork 30.5k
@types/node: Add strings array type to http.request #72617
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
@types/node: Add strings array type to http.request #72617
Conversation
|
@yotamN Thank you for submitting this PR! This is a live comment that I will keep updated. 1 package in this PR
Code ReviewsBecause you edited one package and updated the tests (👏), I can help you merge this PR once someone else signs off on it. You can test the changes of this PR in the Playground. Status
All of the items on the list are green. To merge, you need to post a comment including the string "Ready to merge" to bring in your changes. Diagnostic Information: What the bot saw about this PR{
"type": "info",
"now": "-",
"pr_number": 72617,
"author": "yotamN",
"headCommitOid": "b81fcd8253feee7acdf00bfa37332a03816d244f",
"mergeBaseOid": "1ba22ccfabc63d96ea75922df24043a9cbccf147",
"lastPushDate": "2025-04-27T11:20:24.000Z",
"lastActivityDate": "2025-05-06T05:48:59.000Z",
"maintainerBlessed": "Waiting for Author to Merge (Blessed)",
"mergeOfferDate": "2025-05-06T01:06:59.000Z",
"mergeRequestDate": "2025-05-06T05:48:59.000Z",
"mergeRequestUser": "yotamN",
"hasMergeConflict": false,
"isFirstContribution": false,
"tooManyFiles": false,
"hugeChange": false,
"popularityLevel": "Critical",
"pkgInfo": [
{
"name": "node",
"kind": "edit",
"files": [
{
"path": "types/node/http.d.ts",
"kind": "definition"
},
{
"path": "types/node/test/http.ts",
"kind": "test"
},
{
"path": "types/node/v18/http.d.ts",
"kind": "definition"
},
{
"path": "types/node/v18/test/http.ts",
"kind": "test"
},
{
"path": "types/node/v20/http.d.ts",
"kind": "definition"
},
{
"path": "types/node/v20/test/http.ts",
"kind": "test"
}
],
"owners": [
"Microsoft",
"jkomyno",
"alvis",
"r3nya",
"btoueg",
"smac89",
"touffy",
"DeividasBakanas",
"eyqs",
"Hannes-Magnusson-CK",
"hoo29",
"kjin",
"ajafff",
"islishude",
"mwiktorczyk",
"mohsen1",
"galkin",
"parambirs",
"eps1lon",
"ThomasdenH",
"WilcoBakker",
"wwwy3y3",
"samuela",
"kuehlein",
"bhongy",
"chyzwar",
"trivikr",
"yoursunny",
"qwelias",
"ExE-Boss",
"peterblazejewicz",
"addaleax",
"victorperin",
"NodeJS",
"LinusU",
"wafuwafu13",
"mcollina",
"Semigradsky",
"Renegade334"
],
"addedOwners": [],
"deletedOwners": [],
"popularityLevel": "Critical"
}
],
"reviews": [
{
"type": "approved",
"reviewer": "Renegade334",
"date": "2025-04-29T17:10:46.000Z",
"isMaintainer": false
}
],
"mainBotCommentID": 2833398262,
"ciResult": "pass"
} |
|
🔔 @microsoft @jkomyno @alvis @r3nya @btoueg @smac89 @Touffy @DeividasBakanas @eyqs @Hannes-Magnusson-CK @hoo29 @kjin @ajafff @islishude @mwiktorczyk @mohsen1 @galkin @parambirs @eps1lon @ThomasdenH @WilcoBakker @wwwy3y3 @samuela @kuehlein @bhongy @chyzwar @trivikr @yoursunny @qwelias @ExE-Boss @peterblazejewicz @addaleax @victorperin @nodejs @LinusU @wafuwafu13 @mcollina @Semigradsky @Renegade334 — please review this PR in the next few days. Be sure to explicitly select |
Renegade334
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please also apply these changes to the v18 and v20 branches?
Otherwise, LGTM.
types/node/http.d.ts
Outdated
| defaultPort?: number | string | undefined; | ||
| family?: number | undefined; | ||
| headers?: OutgoingHttpHeaders | undefined; | ||
| headers?: OutgoingHttpHeaders | ReadonlyArray<string> | undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Not enforced, but the convention for the package is along the lines of array-simple – ie. readonly X[] rather than ReadonlyArray<X> for simple array types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
|
@yotamN One or more reviewers has requested changes. Please address their comments. I'll be back once they sign off or you've pushed new commits. Thank you! |
Sure, do I need to just open a separate PR for them? |
DT's branches are tree-based – you just need to apply the same changes to |
|
@Renegade334 Thank you for reviewing this PR! The author has pushed new commits since your last review. Could you take another look and submit a fresh review? |
Okay sure, so I added it |
Renegade334
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
|
Ready to merge |
|
Previously we could access headers by
IMO this is a bug of the type. Please fix. Also I don't really see the advantage of this very change. |
In what context? |
|
Something like this (optional auth - but this is only an example): |
|
I'm not sure what to do with it. |
|
@types/node options interfaces aren't necessarily designed for post-declaration mutability; they're just intended to be an accurate representation of what a particular function or method accepts, and this change ultimately reflects the behaviour of the API. There are still any number of ways of providing the functionality of the example case above: const options: RequestOptions = {
headers: {
'Content-Length': 0,
...userName && { Authorization: 'xxx' },
},
...
}
request(options)etc. |
I see. Sure, there are ways to circumvent the problem. It's a pity, however, if you need to refactor code as a workaround, rendering it less readable.
According to https://nodejs.org/docs/latest/api/http.html#httprequestoptions-callback, "headers" is explicitely defined as an object, nothing else. So I'm not sure where the string array comes from and whether the type should reflect "undocumented" behaviour. |
The latest @types/node changes add `string[]` to the `RequestOptions.headers` type: DefinitelyTyped/DefinitelyTyped#72617 nodejs/node#58049 This PR adds a check and narrow the the type to `http.OutgoingHttpHeaders` before accessing user-agent property. We don't ever set the user agent header using the `string[]` form so this should be fine.
The latest @types/node changes add `string[]` to the `RequestOptions.headers` type: DefinitelyTyped/DefinitelyTyped#72617 nodejs/node#58049 This PR adds a check and narrow the the type to `http.OutgoingHttpHeaders` before accessing user-agent property. We don't ever set the user agent header using the `string[]` form so this should be fine.
The latest @types/node changes add `string[]` to the `RequestOptions.headers` type: DefinitelyTyped/DefinitelyTyped#72617 nodejs/node#58049 This PR adds a check and narrow the type to `http.OutgoingHttpHeaders` before accessing user-agent property. We don't ever set the user agent header using the `string[]` form so this should be fine.
@yotamN @Renegade334 - I'm with @jeffrson here, this is a regression. I noticed it when suddenly hundreds of lines like
The docs show that |
|
Changing the type won't change the fact that |
Please fill in this template.
Use a meaningful title for the pull request. Include the name of the package modified.
Test the change in your own code. (Compile and run.)
Add or edit tests to reflect the change.
Follow the advice from the readme.
Avoid common mistakes.
Run
pnpm test <package to test>.Provide a URL to documentation or source code which provides context for the suggested changes: doc: add Array type in http request headers nodejs/node#58049
If this PR brings the type definitions up to date with a new version of the JS library, update the version number in the
package.json.