Skip to content

Add well-known symbols for ReadonlyMap and ReadonlySet#60142

Closed
milkcask wants to merge 3 commits intomicrosoft:mainfrom
milkcask:readonly-map-set-well-known-symbols
Closed

Add well-known symbols for ReadonlyMap and ReadonlySet#60142
milkcask wants to merge 3 commits intomicrosoft:mainfrom
milkcask:readonly-map-set-well-known-symbols

Conversation

@milkcask
Copy link

@milkcask milkcask commented Oct 5, 2024

Fixes #60042

I chose not to use strict string literals or exact well-known tags like Map and Set for the same reason mentioned in #19006. Instead, I opted to use string. Contra #59417.

@jakebailey
Copy link
Member

@typescript-bot test it

@typescript-bot
Copy link
Collaborator

typescript-bot commented Oct 8, 2024

Starting jobs; this comment will be updated as builds start and complete.

Command Status Results
test top400 ✅ Started 👀 Results
user test this ✅ Started ✅ Results
run dt ✅ Started ✅ Results
perf test this faster ✅ Started 👀 Results

@typescript-bot
Copy link
Collaborator

@jakebailey Here are the results of running the user tests with tsc comparing main and refs/pull/60142/merge:

Everything looks good!

@typescript-bot
Copy link
Collaborator

Hey @jakebailey, the results of running the DT tests are ready.

Everything looks the same!

You can check the log here.

@typescript-bot
Copy link
Collaborator

@jakebailey
The results of the perf run you requested are in!

Here they are:

tsc

Comparison Report - baseline..pr
Metric baseline pr Delta Best Worst p-value
Compiler-Unions - node (v18.15.0, x64)
Errors 31 31 ~ ~ ~ p=1.000 n=6
Symbols 62,340 62,340 ~ ~ ~ p=1.000 n=6
Types 50,379 50,379 ~ ~ ~ p=1.000 n=6
Memory used 193,454k (± 0.74%) 194,004k (± 0.95%) ~ 192,778k 196,424k p=0.810 n=6
Parse Time 1.31s (± 1.24%) 1.31s (± 0.57%) ~ 1.30s 1.32s p=0.564 n=6
Bind Time 0.72s 0.72s ~ ~ ~ p=1.000 n=6
Check Time 9.72s (± 0.38%) 9.75s (± 0.37%) ~ 9.71s 9.80s p=0.227 n=6
Emit Time 2.74s (± 0.63%) 2.72s (± 0.50%) ~ 2.70s 2.74s p=0.118 n=6
Total Time 14.50s (± 0.34%) 14.51s (± 0.26%) ~ 14.45s 14.56s p=0.571 n=6
angular-1 - node (v18.15.0, x64)
Errors 33 33 ~ ~ ~ p=1.000 n=6
Symbols 947,886 947,900 +14 (+ 0.00%) ~ ~ p=0.001 n=6
Types 410,840 410,840 ~ ~ ~ p=1.000 n=6
Memory used 1,224,790k (± 0.01%) 1,224,826k (± 0.01%) ~ 1,224,726k 1,224,933k p=0.297 n=6
Parse Time 8.08s (± 0.63%) 8.06s (± 0.88%) ~ 8.00s 8.20s p=0.293 n=6
Bind Time 2.28s (± 0.64%) 2.27s (± 1.07%) ~ 2.25s 2.31s p=0.570 n=6
Check Time 37.68s (± 0.32%) 37.83s (± 0.28%) ~ 37.71s 38.00s p=0.054 n=6
Emit Time 18.29s (± 0.25%) 18.24s (± 0.36%) ~ 18.14s 18.31s p=0.213 n=6
Total Time 66.33s (± 0.17%) 66.41s (± 0.18%) ~ 66.29s 66.63s p=0.471 n=6
mui-docs - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 2,529,678 2,529,685 +7 (+ 0.00%) ~ ~ p=0.001 n=6
Types 916,161 916,161 ~ ~ ~ p=1.000 n=6
Memory used 2,340,944k (± 0.00%) 2,340,972k (± 0.00%) ~ 2,340,863k 2,341,027k p=0.261 n=6
Parse Time 9.38s (± 0.33%) 9.40s (± 0.30%) ~ 9.35s 9.43s p=0.293 n=6
Bind Time 2.16s (± 0.63%) 2.17s (± 0.54%) ~ 2.15s 2.18s p=0.563 n=6
Check Time 75.79s (± 0.43%) 75.96s (± 0.56%) ~ 75.24s 76.56s p=0.520 n=6
Emit Time 0.28s (± 2.26%) 0.29s (± 2.93%) ~ 0.28s 0.30s p=0.340 n=6
Total Time 87.61s (± 0.37%) 87.82s (± 0.50%) ~ 87.09s 88.46s p=0.378 n=6
self-build-src - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 1,258,109 1,258,214 +105 (+ 0.01%) ~ ~ p=0.001 n=6
Types 266,266 266,266 ~ ~ ~ p=1.000 n=6
Memory used 2,422,499k (± 0.01%) 2,422,523k (± 0.02%) ~ 2,421,826k 2,423,008k p=0.810 n=6
Parse Time 5.21s (± 0.86%) 5.21s (± 0.54%) ~ 5.17s 5.24s p=0.689 n=6
Bind Time 1.93s (± 0.46%) 1.93s (± 0.42%) ~ 1.92s 1.94s p=0.550 n=6
Check Time 35.43s (± 0.49%) 35.47s (± 0.32%) ~ 35.29s 35.63s p=0.575 n=6
Emit Time 3.02s (± 1.95%) 3.02s (± 1.12%) ~ 2.96s 3.06s p=1.000 n=6
Total Time 45.58s (± 0.42%) 45.63s (± 0.29%) ~ 45.44s 45.78s p=0.378 n=6
self-build-src-public-api - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 1,258,109 1,258,214 +105 (+ 0.01%) ~ ~ p=0.001 n=6
Types 266,266 266,266 ~ ~ ~ p=1.000 n=6
Memory used 2,496,191k (± 0.01%) 2,496,124k (± 0.02%) ~ 2,495,470k 2,496,643k p=0.810 n=6
Parse Time 5.38s (± 1.06%) 5.38s (± 0.79%) ~ 5.32s 5.43s p=1.000 n=6
Bind Time 1.73s (± 0.60%) 1.74s (± 0.59%) ~ 1.73s 1.76s p=0.134 n=6
Check Time 35.86s (± 0.22%) 35.88s (± 0.27%) ~ 35.77s 36.03s p=0.748 n=6
Emit Time 3.06s (± 1.03%) 3.04s (± 1.71%) ~ 2.97s 3.09s p=0.936 n=6
Total Time 46.04s (± 0.15%) 46.03s (± 0.16%) ~ 45.94s 46.16s p=0.936 n=6
self-compiler - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 261,786 261,795 +9 (+ 0.00%) ~ ~ p=0.001 n=6
Types 106,508 106,508 ~ ~ ~ p=1.000 n=6
Memory used 438,786k (± 0.01%) 438,801k (± 0.02%) ~ 438,677k 438,888k p=0.575 n=6
Parse Time 3.54s (± 1.12%) 3.55s (± 0.66%) ~ 3.53s 3.58s p=0.466 n=6
Bind Time 1.30s (± 0.49%) 1.31s (± 0.84%) ~ 1.29s 1.32s p=0.080 n=6
Check Time 18.91s (± 0.34%) 18.85s (± 0.68%) ~ 18.66s 19.00s p=0.630 n=6
Emit Time 1.54s (± 0.82%) 1.54s (± 1.59%) ~ 1.50s 1.57s p=0.805 n=6
Total Time 25.29s (± 0.23%) 25.25s (± 0.42%) ~ 25.09s 25.35s p=0.748 n=6
ts-pre-modules - node (v18.15.0, x64)
Errors 68 68 ~ ~ ~ p=1.000 n=6
Symbols 225,919 225,926 +7 (+ 0.00%) ~ ~ p=0.001 n=6
Types 94,415 94,415 ~ ~ ~ p=1.000 n=6
Memory used 371,092k (± 0.01%) 371,122k (± 0.02%) ~ 371,043k 371,175k p=0.377 n=6
Parse Time 3.59s (± 1.10%) 3.57s (± 1.46%) ~ 3.47s 3.62s p=0.744 n=6
Bind Time 1.95s (± 0.72%) 1.94s (± 1.29%) ~ 1.92s 1.99s p=0.460 n=6
Check Time 20.23s (± 0.21%) 20.32s (± 0.08%) +0.09s (+ 0.43%) 20.30s 20.35s p=0.012 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 25.77s (± 0.30%) 25.84s (± 0.28%) ~ 25.72s 25.93s p=0.199 n=6
vscode - node (v18.15.0, x64)
Errors 3 3 ~ ~ ~ p=1.000 n=6
Symbols 3,113,197 3,113,210 +13 (+ 0.00%) ~ ~ p=0.001 n=6
Types 1,073,140 1,073,140 ~ ~ ~ p=1.000 n=6
Memory used 3,206,521k (± 0.00%) 3,206,522k (± 0.01%) ~ 3,206,296k 3,206,725k p=0.936 n=6
Parse Time 14.03s (± 0.53%) 14.03s (± 0.39%) ~ 13.93s 14.09s p=1.000 n=6
Bind Time 4.42s (± 0.75%) 4.44s (± 0.54%) ~ 4.42s 4.48s p=0.376 n=6
Check Time 87.99s (± 2.79%) 87.15s (± 1.60%) ~ 85.06s 88.25s p=0.471 n=6
Emit Time 23.43s (± 7.58%) 25.56s (± 8.90%) ~ 22.55s 27.29s p=0.471 n=6
Total Time 129.88s (± 2.37%) 131.17s (± 2.77%) ~ 126.27s 133.69s p=0.298 n=6
webpack - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 285,172 285,183 +11 (+ 0.00%) ~ ~ p=0.001 n=6
Types 115,780 115,780 ~ ~ ~ p=1.000 n=6
Memory used 435,090k (± 0.02%) 435,063k (± 0.02%) ~ 434,955k 435,199k p=0.687 n=6
Parse Time 4.06s (± 0.40%) 4.03s (± 1.10%) ~ 3.96s 4.08s p=0.197 n=6
Bind Time 1.73s (± 1.24%) 1.75s (± 1.59%) ~ 1.72s 1.78s p=0.293 n=6
Check Time 18.30s (± 0.48%) 18.33s (± 0.53%) ~ 18.17s 18.43s p=0.521 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 24.08s (± 0.39%) 24.11s (± 0.34%) ~ 24.02s 24.23s p=0.630 n=6
xstate-main - node (v18.15.0, x64)
Errors 3 3 ~ ~ ~ p=1.000 n=6
Symbols 540,222 540,239 +17 (+ 0.00%) ~ ~ p=0.001 n=6
Types 181,145 181,145 ~ ~ ~ p=1.000 n=6
Memory used 483,845k (± 0.01%) 483,902k (± 0.01%) ~ 483,856k 483,957k p=0.128 n=6
Parse Time 4.17s (± 0.67%) 4.17s (± 0.59%) ~ 4.13s 4.19s p=0.804 n=6
Bind Time 1.46s (± 0.94%) 1.46s (± 0.83%) ~ 1.44s 1.47s p=1.000 n=6
Check Time 23.71s (± 0.41%) 23.66s (± 0.30%) ~ 23.59s 23.78s p=0.378 n=6
Emit Time 0.00s (±154.76%) 0.00s (±244.70%) ~ 0.00s 0.01s p=0.595 n=6
Total Time 29.34s (± 0.38%) 29.30s (± 0.26%) ~ 29.21s 29.41s p=0.688 n=6
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • Compiler-Unions - node (v18.15.0, x64)
  • angular-1 - node (v18.15.0, x64)
  • mui-docs - node (v18.15.0, x64)
  • self-build-src - node (v18.15.0, x64)
  • self-build-src-public-api - node (v18.15.0, x64)
  • self-compiler - node (v18.15.0, x64)
  • ts-pre-modules - node (v18.15.0, x64)
  • vscode - node (v18.15.0, x64)
  • webpack - node (v18.15.0, x64)
  • xstate-main - node (v18.15.0, x64)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

Developer Information:

Download Benchmarks

@typescript-bot
Copy link
Collaborator

@jakebailey Here are the results of running the top 400 repos with tsc comparing main and refs/pull/60142/merge:

Something interesting changed - please have a look.

Details

angular/angular-cli

8 of 24 projects failed to build with the old tsc and were ignored

tests/legacy-cli/tsconfig.json

@rbuckton
Copy link
Contributor

Copilot AI review requested due to automatic review settings March 24, 2026 21:34
@RyanCavanaugh
Copy link
Member

Closing per #60042 (comment)

@github-project-automation github-project-automation bot moved this from Not started to Done in PR Backlog Mar 24, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a lib.d.ts gap so ReadonlyMap and ReadonlySet include the well-known symbol member [Symbol.toStringTag], aligning them with Map/Set and addressing the keyof/Exclude<> behavior reported in #60042.

Changes:

  • Add readonly [Symbol.toStringTag]: string to ReadonlyMap and ReadonlySet in lib.es2015.symbol.wellknown.d.ts.
  • Add a new conformance test that indexes [Symbol.toStringTag] on ReadonlyMap/ReadonlySet (and related built-ins).
  • Add the corresponding reference baselines (.types, .symbols, .js) for the new test.

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/lib/es2015.symbol.wellknown.d.ts Adds [Symbol.toStringTag] to ReadonlyMap/ReadonlySet via interface merging.
tests/cases/conformance/es6/Symbols/symbolWellKnown.ts New conformance test exercising [Symbol.toStringTag] on ReadonlyMap/ReadonlySet and other types.
tests/baselines/reference/symbolWellKnown.types Baseline for inferred/checked types from the new test.
tests/baselines/reference/symbolWellKnown.symbols Baseline for symbol resolution from the new test.
tests/baselines/reference/symbolWellKnown.js Baseline for JS emit from the new test.

var set = new Set();
set[Symbol.toStringTag];

var readonlySet = <ReadonlySet<any>>new Set();
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

readonlySet is asserted as ReadonlySet<any> while the rest of the file mostly uses unknown, and both readonlyMap/readonlySet use angle-bracket assertions. Using a variable type annotation (and keeping unknown consistent) would avoid any in the baseline and make the intent clearer.

Suggested change
var readonlySet = <ReadonlySet<any>>new Set();
var readonlySet: ReadonlySet<unknown> = new Set();

Copilot uses AI. Check for mistakes.
Comment on lines +9 to +20
var readonlyMap = <ReadonlyMap<unknown, unknown>>new Map();
readonlyMap[Symbol.toStringTag];

var weakMap = new WeakMap();
weakMap[Symbol.toStringTag];

var set = new Set();
set[Symbol.toStringTag];

var readonlySet = <ReadonlySet<any>>new Set();
readonlySet[Symbol.toStringTag];

Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new test verifies that [Symbol.toStringTag] is indexable on ReadonlyMap/ReadonlySet, but it doesn't directly cover the original reported regression scenario where Symbol.toStringTag was unexpectedly included in Exclude<keyof Map, keyof ReadonlyMap> / Exclude<keyof Set, keyof ReadonlySet>. Consider adding type-level assertions (e.g. type ... = Exclude<...> plus // @ts-expect-error assignments using Symbol.toStringTag) so the test fails if Symbol.toStringTag ever drops out of keyof ReadonlyMap/ReadonlySet again.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Backlog Bug PRs that fix a backlog bug

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

ReadonlySet and ReadonlyMap are lacking Symbol.toStringTag

6 participants