Re: [heycam/webidl] A non-optional dictionary argument makes sense at times. (#130)

Sorry to necro this issue, but I just want to put in my opinion that this requirement should change in Web IDL. The intention of the requirement is good, but having it as a strict rule is silly. You should give spec authors good advice but ultimately the leeway to make sensible decisions.

This came up recently with regards to `navigator.share` (see WICG/web-share#47). As with `MutationObserver`, we take a dictionary with all fields optional, but at least one must be supplied. The prose text says to throw a `TypeError` if all fields are missing. Therefore, making it optional has no observable effect (other than changing the `.length`). But it's confusing for anyone casually reading the spec to see "optional" there.

Fixing this is a simple matter of changing "must" to "should" in the following paragraph (bold text indicates my change):

> If the type of an argument is a dictionary type or a union type that has a dictionary as one of its flattened member types, and that dictionary type and its ancestors have no required members, and the argument is either the final argument or is followed only by optional arguments, then the argument **should** be specified as optional.

Another variant, if you want to be stricter but achieve the same effect, is to allow a non-optional dictionary only if `{}` always results in a `TypeError` (as is the case with `MutationObserver` and `navigator.share`):

> If the type of an argument is a dictionary type or a union type that has a dictionary as one of its flattened member types, and that dictionary type and its ancestors have no required members, **and the operation is not guaranteed to throw a `TypeError` when the argument is the empty dictionary value,** and the argument is either the final argument or is followed only by optional arguments, then the argument must be specified as optional.

-- 
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/130#issuecomment-312972577

Received on Wednesday, 5 July 2017 00:58:08 UTC