Emit `Symbol.toStringTag` properties in TS 6.0
Fixes #1641. Fixes #2172. Alternative to #1762. Supersedes #2075.
Reference: https://webidl.spec.whatwg.org/#dfn-class-string
This amends the builder to append Symbol.toStringTag properties to interfaces and iterators in the ts6.0 core libraries. (ES6's well-known symbols are universally defined in ts6.0.)
Because adding a property with a literal type affects inheritance chains, only "final" classes (ie. those that do not have any inheritance children within the current global) can have these properties typed as string literals. (For example, it's not possible for Blob#[Symbol.toStringTag] to be typed as "Blob", because File inherits from Blob, and a property of type "File" can't override a parent property of type "Blob".)
For those interfaces that have one or more inheritance children, there are two possible approaches.
- One is not to emit the property at all – but it's inconsistent to have some interfaces with
Symbol.toStringTagproperties, and others (including some very common ones) without them. - The alternative is to emit properties for these as well, but type them permissively as
string, so that they can be correctly overridden by child interfaces. This is the approach taken here.
The toStringTag emitter does not add to any interface marked noInterfaceObject, since these are usually pseudo-types that are not true IDL interfaces, nor to namespaces converted to interfaces (ie. console).
Thanks for the PR!
This section of the codebase is owned by @saschanaz - if they write a comment saying "LGTM" then it will be merged.