-
Notifications
You must be signed in to change notification settings - Fork 173
Allow dictionaries and callbacks to be distinguishable #1191
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
Comments
It seems like both the union conversion & overload resolution algorithms would already behave sensibly if a dot were added to that grid as both have I thought maybe [LegacyTreatNonObjectAsNull] might have been a factor, but it only does its weird thing when nullable and that would preclude it from being in a union with a dictionary in the cases where it needs to be regardless. I’m less certain if that’s also true for overload distinguishability already. |
I suspect this change could be made in a web-compatible way, but FWIW you could technically use a callback function as a dictionary, since functions are objects.
Probably just making these distinguishable and keeping the current logic whereby the IsCallable check happens before the dictionary conversion. As a consistency point, EventTarget/addEventListener looks more like your second example -- but I don't think that pattern is ubiquitous. |
That’s what I’d expect — the same “fall through” pattern as sequence vs dictionary (or boolean vs number, etc). While I don’t see any trouble for signatures defined this way from the start, the allowance might create the false impression that changing existing signatures in this manner is safe. Maybe a note that explains why extending established dictionary-only signatures through overloading/unions which add callback functions (or sequences) carries a back-compat risk would help? I don’t think it changes what was intended to be conveyed, so this is just FYI: in the Web IDL sense of the term, |
Ohh interesting. I could probably hack this through in the prose.
Yeah, there's also |
Is it any more risky than taking a string argument and introducing an object type? That means code already using that object in the wild will go from being Although, I guess in the wild, folks might be using a constructor function as a dictionary (via 'static' properties). That would pretty significantly change behaviour.
Yeah, it seems like the "callback interface" stuff is only for legacy use. |
It would be good to fix #100 to make the legacy aspect of those clearer. (I'm surprised this is the first issue on making callbacks and dictionaries distinguishable. I looked around a bit and couldn't find anything.) |
I've put up a PR to try and address this. I would appreciate comments: #1353 |
Yay, great to see this land! |
https://webidl.spec.whatwg.org/#dfn-distinguishable
It isn't clear to me why callbacks and dictionaries can't be distinguished.
I'm designing an API like:
But there's a strong possibility that options will be added in future, and I want to avoid this pattern:
And instead go for:
But it seems like I can't overload from
whatever(callback)
towhatever({ callback })
.I would have assumed that an argument could be treated as a callback if it's callable.
The text was updated successfully, but these errors were encountered: