Skip to content

[@types/node] Fix type definitions for node:url#68456

Merged
typescript-bot merged 1 commit intomasterfrom
unknown repository
Feb 15, 2024
Merged

[@types/node] Fix type definitions for node:url#68456
typescript-bot merged 1 commit intomasterfrom
unknown repository

Conversation

@ghost
Copy link

@ghost ghost commented Feb 3, 2024

Fixes #68454

Please fill in this template.

If changing an existing definition:

@ghost ghost requested review from eps1lon and peterblazejewicz as code owners February 3, 2024 05:07
@typescript-bot
Copy link
Contributor

typescript-bot commented Feb 3, 2024

@codershiba Thank you for submitting this PR!

This is a live comment which I will keep updated.

1 package in this PR

Code Reviews

Because this is a widely-used package, a DT maintainer will need to review it before it can be merged.

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 a DT maintainer

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": 68456,
  "author": "codershiba",
  "headCommitOid": "39170046424a5f92a82ea604860cbe7066b7bd7e",
  "mergeBaseOid": "8eef7f48da3124d97c81e44063de0b35729a9064",
  "lastPushDate": "2024-02-03T05:07:57.000Z",
  "lastActivityDate": "2024-02-15T09:41:55.000Z",
  "mergeOfferDate": "2024-02-11T13:38:25.000Z",
  "mergeRequestDate": "2024-02-15T09:41:55.000Z",
  "mergeRequestUser": "codershiba",
  "hasMergeConflict": false,
  "isFirstContribution": false,
  "tooManyFiles": false,
  "hugeChange": false,
  "popularityLevel": "Critical",
  "pkgInfo": [
    {
      "name": "node",
      "kind": "edit",
      "files": [
        {
          "path": "types/node/test/url.ts",
          "kind": "test"
        },
        {
          "path": "types/node/ts4.8/test/url.ts",
          "kind": "test"
        },
        {
          "path": "types/node/ts4.8/url.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/node/ts4.8/wasi.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/node/url.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/node/v16/test/url.ts",
          "kind": "test"
        },
        {
          "path": "types/node/v16/ts4.8/test/url.ts",
          "kind": "test"
        },
        {
          "path": "types/node/v16/ts4.8/url.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/node/v16/url.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/node/v18/test/url.ts",
          "kind": "test"
        },
        {
          "path": "types/node/v18/ts4.8/test/url.ts",
          "kind": "test"
        },
        {
          "path": "types/node/v18/ts4.8/url.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/node/v18/url.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/node/wasi.d.ts",
          "kind": "definition"
        }
      ],
      "owners": [
        "Microsoft",
        "jkomyno",
        "alvis",
        "r3nya",
        "btoueg",
        "smac89",
        "touffy",
        "DeividasBakanas",
        "eyqs",
        "Hannes-Magnusson-CK",
        "hoo29",
        "kjin",
        "ajafff",
        "islishude",
        "mwiktorczyk",
        "mohsen1",
        "n-e",
        "galkin",
        "parambirs",
        "eps1lon",
        "ThomasdenH",
        "WilcoBakker",
        "wwwy3y3",
        "samuela",
        "kuehlein",
        "bhongy",
        "chyzwar",
        "trivikr",
        "yoursunny",
        "qwelias",
        "ExE-Boss",
        "peterblazejewicz",
        "addaleax",
        "victorperin",
        "ZYSzys",
        "NodeJS",
        "LinusU",
        "wafuwafu13",
        "mcollina",
        "Semigradsky"
      ],
      "addedOwners": [],
      "deletedOwners": [],
      "popularityLevel": "Critical"
    }
  ],
  "reviews": [
    {
      "type": "approved",
      "reviewer": "Anonymous4078",
      "date": "2024-02-12T18:54:50.000Z",
      "isMaintainer": false
    },
    {
      "type": "approved",
      "reviewer": "peterblazejewicz",
      "date": "2024-02-11T13:37:46.000Z",
      "isMaintainer": true
    },
    {
      "type": "stale",
      "reviewer": "jakebailey",
      "date": "2024-02-06T10:37:39.000Z",
      "abbrOid": "81f254c"
    },
    {
      "type": "stale",
      "reviewer": "ExE-Boss",
      "date": "2024-02-03T06:38:50.000Z",
      "abbrOid": "4da0f85"
    }
  ],
  "mainBotCommentID": 1925101032,
  "ciResult": "pass"
}

@typescript-bot
Copy link
Contributor

typescript-bot commented Feb 3, 2024

@typescript-bot
Copy link
Contributor

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

@LinusU
Copy link
Contributor

LinusU commented Feb 3, 2024

I'm quite sure that I've seen discussions on this before, but I cannot find it now 🤔

The URL constructor doesn't have any special handling for passing it an URL, it's just that the constructor turns the first argument into a string if it isn't.

ref: https://nodejs.org/api/url.html#new-urlinput-base
spec: https://tc39.es/ecma262/#sec-tostring

There are quite a few other apis that does this, but I don't think that any of them are typed as accepting anything else than string in TypeScript. But it would be equally correct to type this as accepting any, since it will be turned into a string before being parsed.

I don't have a strong opinion either way, but this should probably at least be kept aligned with what the TypeScript DOM typings are doing 🤔 (edit: seems like the TypeScript supplied dom.d.ts declares the constructor as accepting URL)

@ghost
Copy link
Author

ghost commented Feb 3, 2024

@LinusU see #68454

@peterblazejewicz
Copy link
Member

I'd like to point, that in other places, e.g. MIMEType constructor accepts:

constructor(input: string | { toString: () => string });

I'd use dom lib approach though to align types

@ghost
Copy link
Author

ghost commented Feb 3, 2024

I'd like to point, that in other places, e.g. MIMEType constructor accepts:

constructor(input: string | { toString: () => string });

I'd use dom lib approach though to align types

Is the approach taken by the PR not correct?

@peterblazejewicz
Copy link
Member

Is the approach taken by the PR not correct?

No, not at all. Just raised how same problem was solved in other places. TS is all about the shape, so MIMEType approach works too. I'd stick to dom library approach though (where people look for?). So for me PR approach is perfectly sound

@ghost
Copy link
Author

ghost commented Feb 3, 2024

https://github.com/microsoft/TypeScript/blob/main/src/lib/dom.generated.d.ts#L22717

@ghost
Copy link
Author

ghost commented Feb 3, 2024

With the approach

constructor(input: string | { toString: () => string });

TS should error in the following examples but it doesn't

new URL(9); 
new URL([]); 

Now with the current approach

constructor(input: string | URL);
new URL(9); // Errors as expected ✅
new URL([]); // Errors as expected ✅

@peterblazejewicz
Copy link
Member

With the approach

constructor(input: string | { toString: () => string });

I understand, but this example is copied straight from Node docs:

const myURL = new URL({ toString: () => 'https://example.org/' });
// https://example.org/

I'd go to align with dom, if people decide to do so.

@ghost
Copy link
Author

ghost commented Feb 5, 2024

@jakebailey @sandersn Can you take a look here?

@jakebailey
Copy link
Member

Not sure why we're being pinged in particular; is the above feedback in question?

@ghost
Copy link
Author

ghost commented Feb 5, 2024

Not sure why we're being pinged in particular; is the above feedback in question?

Yeah, would like to know what you think about the PR and how I should move forward.

@jakebailey
Copy link
Member

I mean, I think it's moderately unfortunate to be able to pass in anything, but matching DOM and working with a documented example seems preferable.

@ghost ghost marked this pull request as draft February 6, 2024 05:16
@ghost ghost marked this pull request as ready for review February 6, 2024 08:56
@typescript-bot typescript-bot added the The CI failed When GH Actions fails label Feb 6, 2024
@typescript-bot
Copy link
Contributor

@codershiba The CI build failed! Please review the logs for more information.

Once you've pushed the fixes, the build will automatically re-run. Thanks!

Note: builds which are failing do not end up on the list of PRs for the DT maintainers to review.

@ghost ghost marked this pull request as draft February 6, 2024 09:16
@ghost ghost changed the title [@types/node] Make URL constructor accept URL [@types/node] Fix type definitions for node:url Feb 6, 2024
@ghost ghost marked this pull request as ready for review February 6, 2024 09:47
@typescript-bot typescript-bot removed the The CI failed When GH Actions fails label Feb 6, 2024
@ghost ghost requested a review from jakebailey February 6, 2024 11:07
@typescript-bot
Copy link
Contributor

@jakebailey, @ExE-Boss 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?

@ghost
Copy link
Author

ghost commented Feb 8, 2024

@peterblazejewicz Can you take a look here?

@peterblazejewicz
Copy link
Member

so we are sticking that would be nice to have those aligned to dom.lib, though aligning with public docs, that say a contract is more important (for { toString: () => string })
@codershiba

@ghost
Copy link
Author

ghost commented Feb 10, 2024

so we are sticking that would be nice to have those aligned to dom.lib, though aligning with public docs, that say a contract is more important (for { toString: () => string }) @codershiba

I have done some changes few days ago, can you see if that's okay or more changes needs to be done

Copy link
Member

@peterblazejewicz peterblazejewicz left a comment

Choose a reason for hiding this comment

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

LGTM!
@codershiba thanks!

@typescript-bot typescript-bot added Maintainer Approved Self Merge This PR can now be self-merged by the PR author or an owner labels Feb 11, 2024
@typescript-bot
Copy link
Contributor

@codershiba: Everything looks good here. I am ready to merge this PR (at 3917004) on your behalf whenever you think it's ready.

If you'd like that to happen, please post a comment saying:

Ready to merge

and I'll merge this PR almost instantly. Thanks for helping out! ❤️

(@microsoft, @jkomyno, @alvis, @r3nya, @btoueg, @smac89, @Touffy, @DeividasBakanas, @eyqs, @Hannes-Magnusson-CK, @hoo29, @kjin, @ajafff, @islishude, @mwiktorczyk, @mohsen1, @n-e, @galkin, @parambirs, @eps1lon, @ThomasdenH, @WilcoBakker, @wwwy3y3, @samuela, @kuehlein, @bhongy, @chyzwar, @trivikr, @yoursunny, @qwelias, @ExE-Boss, @peterblazejewicz, @addaleax, @victorperin, @ZYSzys, @nodejs, @LinusU, @wafuwafu13, @mcollina, @Semigradsky: you can do this too.)

@typescript-bot typescript-bot added the Other Approved This PR was reviewed and signed-off by a community member. label Feb 12, 2024
@ghost
Copy link
Author

ghost commented Feb 15, 2024

Ready to merge

@typescript-bot typescript-bot merged commit 9705ff4 into DefinitelyTyped:master Feb 15, 2024
@ghost ghost deleted the fix-node-url branch February 15, 2024 09:43
danielbankhead added a commit to googleapis/gaxios that referenced this pull request Oct 29, 2024
* feat!: Standardize `baseURL`

- Remove long-deprecated `baseUrl`
- Use proper `base` URL logic via `new URL(url, base)`

* refactor: Use updated `URL` types

via:
- DefinitelyTyped/DefinitelyTyped#68454
- DefinitelyTyped/DefinitelyTyped#68456

* chore: pin `karma-webpack`
miguelvelezsa pushed a commit to googleapis/google-cloud-node-core that referenced this pull request Oct 13, 2025
* feat!: Standardize `baseURL`

- Remove long-deprecated `baseUrl`
- Use proper `base` URL logic via `new URL(url, base)`

* refactor: Use updated `URL` types

via:
- DefinitelyTyped/DefinitelyTyped#68454
- DefinitelyTyped/DefinitelyTyped#68456

* chore: pin `karma-webpack`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Critical package Maintainer Approved Other Approved This PR was reviewed and signed-off by a community member. 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.

6 participants