Repository navigation
Use aOrB parameter names for union options/primitive parameters - #2577
Samuel Kapust (spkapust) wants to merge 1 commit into
Conversation
|
Thanks for the PR! This section of the codebase is owned by Kagami Sascha Rosylight (@saschanaz) - if they write a comment saying "LGTM" then it will be merged. |
|
@microsoft-github-policy-service agree company="Google" |
|
I'm not sure I like the new names deviating from the spec name. I'd rather switch to multi signature if the parameter name is important. Or maybe we should add comment for parameters instead? Thoughts? Jake Bailey (@jakebailey) |
|
The consensus when we last spoke about it was changing the names instead of multi signature, but happy to hear Jake's latest thoughts as well. |
|
The problem with overloads is that they behave badly when you have unions; you end up being unable to call the overloaded function with one or the other. The only fix is to then introduce more overloads. I honestly don't quite remember where we landed way back then; I had thought you would actually be fixing your tooling rather than the types needing to be updated to make a linter happy? |
|
Hi Jake, |
|
Sorry, I just didn't remember too well, May is decades ago 😄 |
|
No worries! Did you want to proceed with this, go in a different direction, or abandon it? |
|
I'm not super happy but can also accept it if it's needed. But not sure it boosts dev experience as #2470 argues - |
|
I mean, I do wonder why that isn't the better solution? Why not just force the object? |
|
Maybe old browsers? |
|
Yes, they have to maintain backwards compatibility. That's why the object isn't forced. |
|
I agree that dictionary or options bag is better. But because one can use the legacy api, we still want to acknowledge that. What we are trying to avoid is a situation where you have |
|
For our use case, we actually do force the use of the dictionary object when possible. |
|
Regardless of the internal linter rewrite thing, isn't this just better and more descriptive to users/LLMs in terms of autocompletion? Seems awkward to have to go look up MDN in order to determine what the undocumented old literal type in the union means... |
|
I think it'd be fine to do. Maybe Daniel Rosenwasser (@DanielRosenwasser) has some thoughts, though. |
|
I think I generally like it. Ideally instances where you want the names to differ would just have different signatures that we internally unify somehow, but that's a long shot. |
|
|
Also dictionaries are coerced into booleans per Web IDL rule, so I don't really buy the compatibility concern at all... Meaning, |
Full engine support achieved in 2017.
An ancient API, and then an 2026 addition for options, actually...
Full engine support achieved in 2020 (err, by MSEdge migrating to Chromium)
API added in 2023, options added in 2025 🤔
Full browser support achieved in 2022 (MDN argues Safari doesn't support name option but I don't think that is true, it has been there forever since the initial SharedWorker addition) Hmmmmmm. So not really "extreme backward compatibility" maybe. |
|
Like Trevor mentioned, I think the bigger concern here is legibility and descriptiveness rather than compatibility. But yes, as you point out, if we were doing this just for the sake of compatibility, it's not necessarily overkill because these changes aren't that old. |
|
My concern is this downgrades the legibility for dictionaries, which are recommended way to use those APIs. |
|
How is the legibility of dictionaries worsened? We are just trying to indicate that the parameter can be a dictionary OR a literal type. We want the name of the parameter to reflect this and give meaning to what the dictionary or literal type represents. Nothing having to do with the dictionary keys and values is changed in any way. Are you concerned people will get confused over which part of the name represents the literal type and which part of the name represents the dictionary? This is more verbose, but to help me understand your objection here do you think that something like |
|
At the end of the day this isn't something I feel very strongly about. I made this not only because it marginally helps us internally, but mainly because I thought it'd be helpful for the broader TypeScript community to have things properly documented in the code. It was something that personally caused me confusion when I was working on our internal linter and I wanted to prevent others from having that experience. If the consensus is that this isn't worth it, we can close out the issue and abandon this PR. |
|
I think I'm confused where everyone stands. It simultaneously seems like we should do this because the boolean form is still possibly relevant, but maybe not because coercion. But then also this helps a Google internal linter, but the same linter also wants to use the object form, which negates this, or maybe not in some cases? I don't have a strong opinion. I think when we had the meeting a while back we didn't know the scale, and the scale is a lot less bad than I thought because it's really just a handful of declarations (but looks big because it's sigs that are repeated over and over). I don't think the names are too unreadable; TS had similar names for its back compat overloads. |
Fixes #2470
Several web APIs evolved from accepting a single primitive parameter to accepting a union of that primitive and an options/arg dictionary (e.g.,
boolean | AddEventListenerOptions), replacing the original descriptive parameter name with a genericoptionsorargin WebIDL.Following the naming convention already used in upstream WebIDL for similar APIs (such as
IDBObjectStore.getAll(queryOrOptions)andPerformance.measure(name, startOrMeasureOptions)), this change addsoverrideNamesupport for KDL parameter patches and renames the affected union parameters toaOrBform while preserving each spec'soptionsvs.argprefix:EventTarget.addEventListener(and synthesized event-map overloads):options->optionsOrUseCaptureEventTarget.removeEventListener(and synthesized event-map overloads):options->optionsOrUseCaptureDocument.importNode:options->optionsOrDeepElement.scrollIntoView:arg->argOrAlignToTopHTMLElement.togglePopover:options->optionsOrForcenew SharedWorker:options->optionsOrName