Re: [whatwg/webidl] Is a function signature with a parameter type `(DOMString or Interface)` a footgun? (Issue #1604)

linusg left a comment (whatwg/webidl#1604)

We generally avoid coercion for any new APIs, obviously inconsistent with early language design choices but avoiding this kind of footgun. See https://github.com/tc39/how-we-work/blob/main/normative-conventions.md, in particular _Avoid coercing arguments to types other than Boolean_.

A recent similar example is Temporal, which often accepts either a string or Temporal object, e.g. https://tc39.es/proposal-temporal/#sec-temporal.plaindate.from / https://tc39.es/proposal-temporal/#sec-temporal-totemporaldate:

> ToTemporalDate ( item [ , options ] )
>
> 1. If options is not present, set options to undefined.
> 2. If item is an Object, then
>     a. If item has an [[InitializedTemporalDate]] internal slot, then [...]
>     b. If item has an [[InitializedTemporalZonedDateTime]] internal slot, then [...]
>     [...] (fallback for plain temporal-like objects)
> 3. If item is not a String, throw a TypeError exception.
> [...]

Or, if only a primitive is expected: https://tc39.es/ecma262/#sec-uint8array.frombase64

> Uint8Array.fromBase64 ( string [ , options ] )
>
> 1. If string is not a String, throw a TypeError exception.
> [...]

My WebIDL is a bit rusty but I think having some sort of parameter attribute for new APIs that prefers throwing over coercion on type mismatch is worth exploring and would match the current direction of TC39 API surface.

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

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

Received on Thursday, 9 July 2026 08:29:50 UTC