Skip to content

Conversation

@yotamN
Copy link
Contributor

@yotamN yotamN commented Apr 27, 2025

Please fill in this template.

@typescript-bot
Copy link
Contributor

typescript-bot commented Apr 27, 2025

@yotamN Thank you for submitting this PR!

This is a live comment that I will keep updated.

1 package in this PR

Code Reviews

Because 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

  • ✅ No merge conflicts
  • ✅ Continuous integration tests have passed
  • ✅ Most recent commit is approved by type definition owners or DT maintainers

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"
}

@typescript-bot
Copy link
Contributor

@typescript-bot typescript-bot moved this to Waiting for Code Reviews in Pull Request Status Board Apr 27, 2025
@typescript-bot typescript-bot moved this from Waiting for Code Reviews to Needs Maintainer Review in Pull Request Status Board Apr 27, 2025
Copy link
Contributor

@Renegade334 Renegade334 left a 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.

defaultPort?: number | string | undefined;
family?: number | undefined;
headers?: OutgoingHttpHeaders | undefined;
headers?: OutgoingHttpHeaders | ReadonlyArray<string> | undefined;
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@typescript-bot typescript-bot added the Revision needed This PR needs code changes before it can be merged. label Apr 28, 2025
@typescript-bot
Copy link
Contributor

@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!

@typescript-bot typescript-bot moved this from Needs Maintainer Review to Needs Author Action in Pull Request Status Board Apr 28, 2025
@yotamN
Copy link
Contributor Author

yotamN commented Apr 29, 2025

Can you please also apply these changes to the v18 and v20 branches?

Otherwise, LGTM.

Sure, do I need to just open a separate PR for them?

@typescript-bot typescript-bot removed the Revision needed This PR needs code changes before it can be merged. label Apr 29, 2025
@typescript-bot typescript-bot moved this from Needs Author Action to Waiting for Code Reviews in Pull Request Status Board Apr 29, 2025
@Renegade334
Copy link
Contributor

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 /types/node/{v18,v20}/....

@typescript-bot typescript-bot moved this from Waiting for Code Reviews to Needs Maintainer Review in Pull Request Status Board Apr 29, 2025
@typescript-bot
Copy link
Contributor

@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?

@yotamN
Copy link
Contributor Author

yotamN commented Apr 29, 2025

DT's branches are tree-based – you just need to apply the same changes to /types/node/{v18,v20}/....

Okay sure, so I added it

@typescript-bot typescript-bot moved this from Needs Maintainer Review to Waiting for Code Reviews in Pull Request Status Board Apr 29, 2025
@typescript-bot typescript-bot moved this from Waiting for Code Reviews to Needs Maintainer Review in Pull Request Status Board Apr 29, 2025
Copy link
Contributor

@Renegade334 Renegade334 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@typescript-bot typescript-bot added the Owner Approved A listed owner of this package signed off on the pull request. label Apr 29, 2025
@RyanCavanaugh RyanCavanaugh moved this from Needs Maintainer Review to Waiting for Code Reviews (Blessed) in Pull Request Status Board May 5, 2025
@typescript-bot typescript-bot added the Self Merge This PR can now be self-merged by the PR author or an owner label May 6, 2025
@typescript-bot typescript-bot moved this from Waiting for Code Reviews (Blessed) to Waiting for Author to Merge (Blessed) in Pull Request Status Board May 6, 2025
@yotamN
Copy link
Contributor Author

yotamN commented May 6, 2025

Ready to merge

@typescript-bot typescript-bot moved this from Waiting for Author to Merge (Blessed) to Recently Merged in Pull Request Status Board May 6, 2025
@typescript-bot typescript-bot merged commit 508e8fc into DefinitelyTyped:master May 6, 2025
15 checks passed
@jeffrson
Copy link
Contributor

jeffrson commented May 7, 2025

Previously we could access headers by options.headers.Authorization, which is no longer allowed due to this change:

Property 'Authorization' does not exist on type 'OutgoingHttpHeaders | readonly string[]'.
Property 'Authorization' does not exist on type 'readonly string[]'.ts(2339)

IMO this is a bug of the type. Please fix.

Also I don't really see the advantage of this very change.

@Renegade334
Copy link
Contributor

Previously we could access headers by options.headers.Authorization

In what context?

@jeffrson
Copy link
Contributor

jeffrson commented May 7, 2025

Something like this (optional auth - but this is only an example):

            const options: RequestOptions = { headers: { 'Content-Length': 0 }, ...}

            if (userName) {
                options.headers.Authorization = ...
            }

@yotamN
Copy link
Contributor Author

yotamN commented May 7, 2025

I'm not sure what to do with it.
From your code snippet I understand why it breaks backward compatibility but my update just fixed the type to represent the actual implementation.
Yes, you can't assume that the headers is an object and the fact that you could until now was a bug.

@Renegade334
Copy link
Contributor

@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.

@jeffrson
Copy link
Contributor

jeffrson commented May 8, 2025

@types/node options interfaces aren't necessarily designed for post-declaration mutability

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.

you can't assume that the headers is an object

this change ultimately reflects the behaviour of the API

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.

jeremymeng added a commit to jeremymeng/azure-sdk-for-js that referenced this pull request May 12, 2025
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.
jeremymeng added a commit to jeremymeng/azure-sdk-for-js that referenced this pull request May 12, 2025
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.
jeremymeng added a commit to Azure/azure-sdk-for-js that referenced this pull request May 12, 2025
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.
@mdmower-csnw
Copy link
Contributor

mdmower-csnw commented Jul 6, 2025

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.

@yotamN @Renegade334 - I'm with @jeffrson here, this is a regression. I noticed it when suddenly hundreds of lines like reqOpts.headers.cookie caused error

Property 'cookie' does not exist on type 'OutgoingHttpHeaders | readonly string[]'.

The docs show that headers should be an object. This change should be reverted.

@yotamN yotamN deleted the node-http-request-headers branch July 6, 2025 15:12
@yotamN
Copy link
Contributor Author

yotamN commented Jul 6, 2025

Changing the type won't change the fact that http.request can receive an array of strings.
The docs are not up to date but you can see that the PR have been merged, meaning you will see it there in the next release.

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

Labels

Critical package Owner Approved A listed owner of this package signed off on the pull request. Self Merge This PR can now be self-merged by the PR author or an owner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants