Open lionel-rowe opened 1 month ago
Is there any reason not to simply have the Map
interface extend ReadonlyMap
(and same for Set
and Array
)?
These are well known symbols of es2015.
https://262.ecma-international.org/6.0/#sec-well-known-symbols
It first appears to be safer to use the exact well-known tags rather than string
, as done in a recent PR https://github.com/microsoft/TypeScript/pull/59417. Yet, I don't think it's proper after considering https://github.com/microsoft/TypeScript/issues/19006.
These interfaces do not describe actual ECMAScript constructors. Adding Symbol.toStringTag
to them would be a breaking change for anyone implementing Map- or Set-like objects/classes that are currently assignment-compatible with ReadonlyMap
/ReadonlySet
, such as the custom maps uses in DeoptExplorer
@rbuckton I don't have a strong opinion on this one; I just found it and fixed it. That said, here's a reason we might want to add Symbol.toStringTag
.
ReadonlyMap
is also used to provide interfaces for the read-only browser Map-like objects.
For example,
interface EventCounts extends ReadonlyMap<string, number> {}
and at runtime,
>> performance.eventCounts
-----
EventCounts { size: 1 }
constructor: function EventCounts()
Symbol(Symbol.toStringTag): "EventCounts"
[...]
[...]
It seems ReadonlyMap does describe Map and the expectation that it is readonly.
🔎 Search Terms
ReadonlySet
,ReadonlyMap
,Symbol.toStringTag
🕗 Version & Regression Information
This is the behavior in every version I tried, and I reviewed the FAQ for entries about
ReadonlySet
,ReadonlyMap
,Symbol.toStringTag
⏯ Playground Link
https://www.typescriptlang.org/play/?target=99#code/C4TwDgpgBAsgrsAhsAlgOwOY0WGFgAWA9gCYByiAttALxQCiAHgMYA2cJEAPANYQhEAZrBxc4aHmiIB3NABoo4yTLQA+BXwHCAShEQkiaViGxgxEqbIVLLa1QChQkWAmToMAZXx5CpCtSg6JjYObk0hKC9gc2VZdShwnT0DIxAomNtVB3sAehyoAAFgAGcAWghGSGZgcoAnWqJa+1Z8KEQALhckVExTH2JyKlpIkEoAIyJWADpgIg9gWvcAFUQMXPyisoqqmoh6xubWsc74bvco-r8hwJHxyZm5heXV+yA
💻 Code
🙁 Actual behavior
Both
@ts-expect-error
s giveUnused '@ts-expect-error' directive.(2578)
🙂 Expected behavior
Both
@ts-expect-error
s are usedAdditional information about the issue
No response