Emit Symbol.toStringTag
properties in TS 6.0
#2193
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Symbol.toStringTag
properties, and others (including some very common ones) without them.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
).Also adds a
noToStringTag
interface property to explicitly suppress emitting aSymbol.toStringTag
property. This is useful for interfaces known to be a common target for userland inheritance, for exampleDOMException
, which would otherwise be emitted within audioworklet.