- From: Domenic Denicola <notifications@github.com>
- Date: Mon, 27 Jul 2020 14:51:51 -0700
- To: heycam/webidl <webidl@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <heycam/webidl/issues/903@github.com>
This is a continuation of https://github.com/heycam/webidl/issues/130. There are a number of places on the platform that end up marking their dictionary arguments as "optional", even though they're not really optional. They just have a requirement that can't be expressed in IDL today: at least one member must be present. Examples: - DOM's [MutationObserverInit](https://dom.spec.whatwg.org/#dom-mutationobserver-observe) (I think... it's a bit complicated) - Web Share's [ShareData](https://w3c.github.io/web-share/#share-method) - Media Capture and Stream's [MediaStreamConstraints](https://w3c.github.io/mediacapture-main/#dom-mediadevices-getusermedia) (although they'd need to remove the default `= false` values, otherwise both members are always present) - The planned [URLPatternInit](https://github.com/wanderview/service-worker-scope-pattern-matching/blob/master/explainer.md#urlpattern) I think we might have reached the point where it's worth making this pattern first-class. It would remove a bit of spec boilerplate in each spec, _and_ it would make the IDL less confusing for readers (see e.g. https://github.com/whatwg/dom/issues/332). I suggest something like ```webidl partial interface MutationObserver { void observe(Node target, [OneMemberRequired] MutationObserverInit options); }; ``` I believe this explicitness sidesteps the problems mentioned in #130, where we were worried that people would not properly mark truly-optional trailing dictionaries as optional. You have to really know what you're doing to use this kind of extended attribute. We could also use a keyword (`onememberrequired MutationObserverInit options`) for symmetry with `optional`. In general the dividing line between syntax and extended attributes is kind of blurry in Web IDL; see some discussion in https://github.com/heycam/webidl/pull/857#issuecomment-604388055. -- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/heycam/webidl/issues/903
Received on Monday, 27 July 2020 21:52:05 UTC