-
Notifications
You must be signed in to change notification settings - Fork 453
Description
DOMString
, USVString
, CSSOMString
and ByteString
are currently mapped to simply string
:
...[...stringTypes].map((type) => [type, "string"] as [string, string]), |
However it doesn't include objects that can be stringified using the ToString
abstract operation.
For example, the following code is valid in JavaScript but doesn't compile in TypeScript:
new URL(window.location); // Error: Argument of type 'Location' is not assignable to parameter of type 'string'.
So I think this is a more general case of #331.
A possible solution would be to map them to string | { toString(): string }
instead, but that would pollute many DOM APIs. For example, it would make even the following code to compile without errors, which is not necessarily desired:
new URL({ toString() { return "hello"; } });
A restriction that can be made is allowing only interfaces with stringifiers (URL
is among them). From my understanding there are not so many such interfaces, so this wouldn't be much wider than string
.