Skip to content

Conversation

@antongolub
Copy link
Contributor

@antongolub antongolub commented Feb 5, 2022

relates #58277 #34960

  • 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.)

CC @sandersn, @SimonSchick

@typescript-bot
Copy link
Contributor

typescript-bot commented Feb 5, 2022

@antongolub 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
  • ✅ Only a DT maintainer can approve changes without tests

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": 58619,
  "author": "antongolub",
  "headCommitOid": "aded305520919755420981d6a6e45c16af07bc65",
  "mergeBaseOid": "00dc9f1849e5a8a43a662bcb8add51e22135e3c0",
  "lastPushDate": "2022-02-10T06:08:26.000Z",
  "lastActivityDate": "2022-02-14T19:05:18.000Z",
  "mergeOfferDate": "2022-02-14T18:49:50.000Z",
  "mergeRequestDate": "2022-02-14T19:05:18.000Z",
  "mergeRequestUser": "antongolub",
  "hasMergeConflict": false,
  "isFirstContribution": false,
  "tooManyFiles": false,
  "hugeChange": false,
  "popularityLevel": "Critical",
  "pkgInfo": [
    {
      "name": "node",
      "kind": "edit",
      "files": [
        {
          "path": "types/node/url.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/node/v12/url.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/node/v14/url.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/node/v16/url.d.ts",
          "kind": "definition"
        }
      ],
      "owners": [
        "Microsoft",
        "DefinitelyTyped",
        "jkomyno",
        "alvis",
        "r3nya",
        "btoueg",
        "smac89",
        "touffy",
        "DeividasBakanas",
        "eyqs",
        "Hannes-Magnusson-CK",
        "hoo29",
        "kjin",
        "ajafff",
        "islishude",
        "mwiktorczyk",
        "mohsen1",
        "n-e",
        "galkin",
        "parambirs",
        "eps1lon",
        "SimonSchick",
        "ThomasdenH",
        "WilcoBakker",
        "wwwy3y3",
        "samuela",
        "kuehlein",
        "bhongy",
        "chyzwar",
        "trivikr",
        "yoursunny",
        "qwelias",
        "ExE-Boss",
        "peterblazejewicz",
        "addaleax",
        "victorperin",
        "ZYSzys",
        "NodeJS",
        "LinusU",
        "wafuwafu13"
      ],
      "addedOwners": [],
      "deletedOwners": [],
      "popularityLevel": "Critical"
    }
  ],
  "reviews": [
    {
      "type": "approved",
      "reviewer": "rbuckton",
      "date": "2022-02-14T18:49:13.000Z",
      "isMaintainer": true
    },
    {
      "type": "stale",
      "reviewer": "sandersn",
      "date": "2022-02-07T18:56:16.000Z",
      "abbrOid": "ba3ac37"
    }
  ],
  "mainBotCommentID": 1030577013,
  "ciResult": "pass"
}

@typescript-bot typescript-bot added Critical package Untested Change This PR does not touch tests labels Feb 5, 2022
@typescript-bot
Copy link
Contributor

Hey @antongolub,

😒 Your PR doesn't modify any tests, so it's hard to know what's being fixed, and your changes might regress in the future. Please consider adding tests to cover the change you're making. Including tests allows this PR to be merged by yourself and the owners of this module.

This can potentially save days of time for you!

@typescript-bot
Copy link
Contributor

@typescript-bot typescript-bot added the The CI failed When GH Actions fails label Feb 5, 2022
@typescript-bot
Copy link
Contributor

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

@antongolub antongolub force-pushed the fix-node-global-url-for-lib-webworker branch from e0006d8 to ba3ac37 Compare February 5, 2022 18:42
@typescript-bot typescript-bot removed the The CI failed When GH Actions fails label Feb 5, 2022
Copy link
Contributor

@sandersn sandersn left a comment

Choose a reason for hiding this comment

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

I don't like it, but it seems necessary to get this working everywhere.

I'd sign off, but I want to see if some node types maintainers can comment as well.

@antongolub
Copy link
Contributor Author

antongolub commented Feb 7, 2022

I look to the future with optimism: TS is being improved step by step, day by day and over time we will be able to remove all these workarounds.

@typescript-bot
Copy link
Contributor

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

@rbuckton rbuckton changed the title fix(node): make global ULR decl compatible with lib "webworker" fix(node): make global URL decl compatible with lib "webworker" Feb 9, 2022
var URL: typeof globalThis extends { webkitURL: infer URL } ? URL : typeof _URL;
var URL:
// For compatibility with "dom" and "webworker" URL declarations
typeof globalThis extends { onmessage: infer O, URL: infer URL }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Isn't this circular? Declaring var URL in a global augmentation means that globalThis will have a URL even if it isn't defined elsewhere, so you might as well just be testing for { onmessage: any }. The previous check tested the presence of webkitURL, which would not be circular.

Also, why are you using infer O? The resulting type variable isn't used anywhere else.

Copy link
Contributor Author

@antongolub antongolub Feb 10, 2022

Choose a reason for hiding this comment

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

  1. Seems that there's no infinite recursion for URL because the onmessage type check goes first. Should I replace the current one with smth like this?
var URL:
  // For compatibility with "dom" and "webworker" URL declarations
  typeof globalThis extends { onmessage: any }
    ? typeof globalThis.URL
    : typeof _URL;
  1. removed redundant infer O

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

typeof globalThis.URL is still circular, because it just references the URL you've defined if nothing else is present. The previous code could use webkitURL because it was a different declaration. Unfortunately, lib.webworker.generated.d.ts doesn't have a different definition of URL to infer from, though maybe you could do something like this:

var URL: 
  // for compatibility with "dom" URL
  typeof globalThis extends { webkitURL: infer URL } ? URL :
  // for compatibility with "webworker" URL
  typeof globalThis extends { WebSocket: new (url: string | infer URL) => any } ? URL :
  typeof _URL;

Though the WebSocket variant could work for both dom and webworker.

Copy link
Contributor Author

@antongolub antongolub Feb 14, 2022

Choose a reason for hiding this comment

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

ok, if typeof globalThis.URL is still circular, why tsc does not raise an error (error TS2502: 'URL' is referenced directly or indirectly in its own type annotation.)? Doesn't that mean, it refers to the URL defined by lib.dom/lib.webworker?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Honestly, I'm surprised it's not an error. If you remove "dom" from the "lib" section in the tsconfig and change the type to var URL: typeof globalThis.URL then it is an error, but the conditional type keeps that from happening.

@typescript-bot
Copy link
Contributor

@rbuckton, @sandersn 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?

@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 14, 2022
@typescript-bot
Copy link
Contributor

@antongolub: Everything looks good here. I am ready to merge this PR (at aded305) 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, @DefinitelyTyped, @jkomyno, @alvis, @r3nya, @btoueg, @smac89, @Touffy, @DeividasBakanas, @eyqs, @Hannes-Magnusson-CK, @hoo29, @kjin, @ajafff, @islishude, @mwiktorczyk, @mohsen1, @n-e, @galkin, @parambirs, @eps1lon, @SimonSchick, @ThomasdenH, @WilcoBakker, @wwwy3y3, @samuela, @kuehlein, @bhongy, @chyzwar, @trivikr, @yoursunny, @qwelias, @ExE-Boss, @peterblazejewicz, @addaleax, @victorperin, @ZYSzys, @nodejs, @LinusU, @wafuwafu13: you can do this too.)

@antongolub
Copy link
Contributor Author

Ready to merge

martin-badin pushed a commit to martin-badin/DefinitelyTyped that referenced this pull request Feb 23, 2022
…atible with lib "webworker" by @antongolub

* fix(node): make global ULR decl compatible with lib "webworker"

relates DefinitelyTyped#58277 DefinitelyTyped#34960

* fix(node): improve global URL var type resolution

* refactor(node): handle URLSeachParams var type collision in the same way as for URL

* refactor(node): simplify type condition for global URL and URLSearchParams
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Critical package Maintainer Approved Self Merge This PR can now be self-merged by the PR author or an owner Untested Change This PR does not touch tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants