[whatwg/webidl] Detect whether a dictionary member was set by default or not (Issue #1300)

It would be nice if WebIDL would provide a way to know whether a dictionary member was set by default or not.

```webidl
dictionary MyDictionary {
    required boolean myRequiredMember;
    boolean myOptionalMember = false;
};
```

In that case, `myOptionalMember` could be `false` because it was either set explicitly by developer with `{ myRequiredMember: true, myOptionalMember: false }` or because it was not with `{ myRequiredMember: true }`.
  
Having a way to detect this would allow implementations to warn developers that a dictionary was partially specified which may result in unexpected behaviour.  For instance, `{ myRequiredMember: true, myOptionalMemberWithTypo: true }` would set `myOptionalMember` to `false`.

Some would argue that if it's the case dictionary members should be declared `required`. I'm not sure about it. Providing default values is good but typos exist. I'd like to see efforts on that front.





-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/webidl/issues/1300
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/webidl/issues/1300@github.com>

Received on Friday, 28 April 2023 08:42:17 UTC