-
Notifications
You must be signed in to change notification settings - Fork 30.5k
fix(node): make global URL decl compatible with lib "webworker" #58619
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
fix(node): make global URL decl compatible with lib "webworker" #58619
Conversation
|
@antongolub Thank you for submitting this PR! This is a live comment which I will keep updated. 1 package in this PRCode ReviewsBecause 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
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"
} |
|
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! |
|
🔔 @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 — please review this PR in the next few days. Be sure to explicitly select |
|
@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. |
e0006d8 to
ba3ac37
Compare
sandersn
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.
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.
|
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. |
|
@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? |
types/node/url.d.ts
Outdated
| 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 } |
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.
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.
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.
- Seems that there's no infinite recursion for
URLbecause theonmessagetype 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;- removed redundant
infer O
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.
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.
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.
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.
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?
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.
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.
|
@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:
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.) |
|
Ready to merge |
…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
relates #58277 #34960
CC @sandersn, @SimonSchick