Skip to content

fixed types for Object.values and Object.entries - #58358

Closed
typeholes wants to merge 3 commits into
microsoft:mainfrom
typeholes:fix26010
Closed

fixed types for Object.values and Object.entries#58358
typeholes wants to merge 3 commits into
microsoft:mainfrom
typeholes:fix26010

Conversation

@typeholes

Copy link
Copy Markdown

Fixes#26010

@typescript-botTypeScript Bot (typescript-bot) added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Apr 29, 2024
@jakebailey

Copy link
Copy Markdown
Member

@typescript-bot

TypeScript Bot (typescript-bot) commented Apr 29, 2024

Copy link
Copy Markdown
Contributor

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

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

@typescript-bot

Copy link
Copy Markdown
Contributor

Hey Jake Bailey (@jakebailey), the results of running the DT tests are ready.

Everything looks the same!

You can check the log here.

@typescript-bot

Copy link
Copy Markdown
Contributor

Jake Bailey (@jakebailey) Here are the results of running the user tests comparing main and refs/pull/58358/merge:

Everything looks good!

@typescript-bot

Copy link
Copy Markdown
Contributor

Jake Bailey (@jakebailey)
The results of the perf run you requested are in!

Here they are:

tsc

Comparison Report - baseline..pr
MetricbaselineprDeltaBestWorstp-value
Compiler-Unions - node (v18.15.0, x64)
Errors3030~~~p=1.000 n=6
Symbols62,15462,154~~~p=1.000 n=6
Types50,27350,273~~~p=1.000 n=6
Memory used193,415k (± 0.92%)194,619k (± 0.98%)~192,137k196,010kp=0.378 n=6
Parse Time1.34s (± 1.38%)1.35s (± 0.30%)~1.35s1.36sp=0.787 n=6
Bind Time0.72s (± 0.57%)0.72s~~~p=0.405 n=6
Check Time9.58s (± 0.32%)9.62s (± 0.30%)~9.57s9.65sp=0.077 n=6
Emit Time2.61s (± 0.38%)2.62s (± 0.57%)~2.61s2.65sp=0.209 n=6
Total Time14.26s (± 0.29%)14.32s (± 0.21%)+0.06s (+ 0.42%)14.26s14.34sp=0.024 n=6
angular-1 - node (v18.15.0, x64)
Errors55~~~p=1.000 n=6
Symbols945,172945,416+244 (+ 0.03%)~~p=0.001 n=6
Types408,068407,894-174 (- 0.04%)~~p=0.001 n=6
Memory used1,221,990k (± 0.00%)1,222,117k (± 0.00%)+127k (+ 0.01%)1,222,053k1,222,171kp=0.008 n=6
Parse Time8.23s (± 0.76%)8.22s (± 0.51%)~8.15s8.28sp=0.936 n=6
Bind Time2.24s (± 0.75%)2.24s (± 0.59%)~2.22s2.25sp=0.933 n=6
Check Time36.68s (± 0.30%)36.63s (± 0.31%)~36.48s36.74sp=0.471 n=6
Emit Time17.43s (± 0.34%)17.44s (± 0.45%)~17.34s17.55sp=1.000 n=6
Total Time64.57s (± 0.24%)64.53s (± 0.32%)~64.27s64.80sp=0.689 n=6
mui-docs - node (v18.15.0, x64)
Errors55~~~p=1.000 n=6
Symbols1,955,8701,955,915+45 (+ 0.00%)~~p=0.001 n=6
Types676,290676,279-11 (- 0.00%)~~p=0.001 n=6
Memory used1,754,518k (± 0.00%)1,754,514k (± 0.00%)~1,754,420k1,754,558kp=1.000 n=6
Parse Time8.11s (± 0.40%)8.09s (± 0.34%)~8.04s8.12sp=0.329 n=6
Bind Time2.72s (± 0.49%)2.73s (± 0.55%)~2.72s2.76sp=0.249 n=6
Check Time67.07s (± 0.42%)67.24s (± 0.37%)~66.97s67.56sp=0.297 n=6
Emit Time0.16s (± 4.99%)0.17s (± 6.19%)~0.16s0.18sp=0.595 n=6
Total Time78.07s (± 0.38%)78.23s (± 0.31%)~77.98s78.57sp=0.336 n=6
self-build-src - node (v18.15.0, x64)
Errors00~~~p=1.000 n=6
Symbols1,215,6691,216,532+863 (+ 0.07%)~~p=0.001 n=6
Types257,620257,489-131 (- 0.05%)~~p=0.001 n=6
Memory used2,323,692k (± 0.02%)2,382,197k (± 6.00%)~2,322,934k2,674,296kp=0.936 n=6
Parse Time7.62s (± 0.64%)7.56s (± 0.60%)~7.49s7.63sp=0.054 n=6
Bind Time2.75s (± 0.88%)2.75s (± 0.38%)~2.73s2.76sp=0.293 n=6
Check Time49.51s (± 0.64%)49.00s (± 0.84%)-0.52s (- 1.04%)48.42s49.45sp=0.045 n=6
Emit Time3.92s (± 0.50%)3.84s (± 2.14%)-0.08s (- 2.04%)3.72s3.94sp=0.045 n=6
Total Time63.80s (± 0.55%)63.14s (± 0.67%)-0.66s (- 1.04%)62.65s63.65sp=0.020 n=6
self-build-src-public-api - node (v18.15.0, x64)
Errors00~~~p=1.000 n=6
Symbols1,215,6691,216,532+863 (+ 0.07%)~~p=0.001 n=6
Types257,620257,489-131 (- 0.05%)~~p=0.001 n=6
Memory used2,397,921k (± 0.01%)2,398,508k (± 0.01%)+588k (+ 0.02%)2,398,055k2,398,833kp=0.020 n=6
Parse Time6.34s (± 0.30%)6.34s (± 0.19%)~6.32s6.35sp=1.000 n=6
Bind Time2.01s (± 0.68%)2.02s (± 0.94%)~2.00s2.04sp=0.218 n=6
Check Time40.55s (± 0.18%)40.06s (± 0.25%)-0.49s (- 1.22%)39.95s40.24sp=0.005 n=6
Emit Time3.13s (± 0.89%)3.13s (± 1.30%)~3.10s3.21sp=0.810 n=6
Total Time52.03s (± 0.14%)51.56s (± 0.18%)-0.47s (- 0.91%)51.47s51.73sp=0.005 n=6
self-compiler - node (v18.15.0, x64)
Errors00~~~p=1.000 n=6
Symbols256,176256,241+65 (+ 0.03%)~~p=0.001 n=6
Types103,637103,527-110 (- 0.11%)~~p=0.001 n=6
Memory used424,282k (± 0.01%)424,309k (± 0.01%)~424,264k424,334kp=0.149 n=6
Parse Time3.50s (± 0.72%)3.49s (± 1.15%)~3.42s3.52sp=0.871 n=6
Bind Time1.30s (± 1.26%)1.30s (± 1.02%)~1.28s1.32sp=0.615 n=6
Check Time18.29s (± 0.19%)17.78s (± 0.39%)-0.51s (- 2.79%)17.70s17.86sp=0.005 n=6
Emit Time1.36s (± 2.00%)1.38s (± 2.22%)~1.34s1.42sp=0.468 n=6
Total Time24.46s (± 0.17%)23.95s (± 0.43%)-0.51s (- 2.09%)23.79s24.07sp=0.005 n=6
ts-pre-modules - node (v18.15.0, x64)
Errors3535~~~p=1.000 n=6
Symbols224,824224,845+21 (+ 0.01%)~~p=0.001 n=6
Types93,39093,394+4 (+ 0.00%)~~p=0.001 n=6
Memory used369,312k (± 0.01%)369,346k (± 0.01%)~369,304k369,388kp=0.066 n=6
Parse Time3.67s (± 0.30%)3.66s (± 0.61%)~3.63s3.68sp=0.365 n=6
Bind Time1.93s (± 1.17%)1.93s (± 0.76%)~1.91s1.95sp=0.935 n=6
Check Time19.41s (± 0.32%)19.40s (± 0.18%)~19.36s19.45sp=1.000 n=6
Emit Time0.00s0.00s~~~p=1.000 n=6
Total Time25.02s (± 0.26%)24.99s (± 0.12%)~24.95s25.03sp=0.808 n=6
vscode - node (v18.15.0, x64)
Errors44~~~p=1.000 n=6
Symbols2,798,8522,798,955+103 (+ 0.00%)~~p=0.001 n=6
Types950,749950,678-71 (- 0.01%)~~p=0.001 n=6
Memory used2,926,479k (± 0.00%)2,926,449k (± 0.00%)~2,926,343k2,926,701kp=0.378 n=6
Parse Time16.65s (± 0.41%)16.68s (± 0.48%)~16.53s16.75sp=0.575 n=6
Bind Time4.97s (± 0.45%)5.05s (± 1.91%)+0.08s (+ 1.58%)4.98s5.24sp=0.015 n=6
Check Time88.91s (± 0.49%)88.92s (± 0.34%)~88.40s89.21sp=0.810 n=6
Emit Time26.22s (± 9.58%)26.95s (± 8.80%)~23.83s28.62sp=1.000 n=6
Total Time136.75s (± 1.93%)137.61s (± 1.67%)~134.46s139.26sp=0.873 n=6
webpack - node (v18.15.0, x64)
Errors00~~~p=1.000 n=6
Symbols265,853265,957+104 (+ 0.04%)~~p=0.001 n=6
Types108,438108,476+38 (+ 0.04%)~~p=0.001 n=6
Memory used410,404k (± 0.02%)410,561k (± 0.02%)+157k (+ 0.04%)410,448k410,667kp=0.013 n=6
Parse Time4.87s (± 0.49%)4.88s (± 0.46%)~4.85s4.91sp=0.415 n=6
Bind Time2.07s (± 1.04%)2.07s (± 0.79%)~2.04s2.09sp=0.869 n=6
Check Time21.12s (± 0.21%)21.09s (± 0.24%)~21.00s21.13sp=0.170 n=6
Emit Time0.00s0.00s~~~p=1.000 n=6
Total Time28.07s (± 0.29%)28.03s (± 0.21%)~27.96s28.09sp=0.630 n=6
xstate-main - node (v18.15.0, x64)
Errors00~~~p=1.000 n=6
Symbols523,981524,002+21 (+ 0.00%)~~p=0.001 n=6
Types178,708178,702-6 (- 0.00%)~~p=0.001 n=6
Memory used461,255k (± 0.01%)461,299k (± 0.02%)~461,223k461,396kp=0.575 n=6
Parse Time2.70s (± 0.68%)2.69s (± 0.45%)~2.67s2.70sp=0.162 n=6
Bind Time0.98s0.98s (± 0.64%)~0.97s0.99sp=1.000 n=6
Check Time15.50s (± 0.12%)15.45s (± 0.77%)~15.21s15.53sp=0.627 n=6
Emit Time0.00s0.00s~~~p=1.000 n=6
Total Time19.18s (± 0.14%)19.12s (± 0.62%)~18.88s19.19sp=0.294 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)
BenchmarkNameIterations
Currentpr6
Baselinebaseline6

Developer Information:

Download Benchmarks

@typescript-bot

Copy link
Copy Markdown
Contributor

Jake Bailey (@jakebailey) Here are the results of running the top 400 repos comparing main and refs/pull/58358/merge:

Everything looks good!

@typeholes
typeholes marked this pull request as ready for review April 30, 2024 14:58
@typeholes

Copy link
Copy Markdown
Author

Once #58372 🙂 lands the overload should probably be replaced by a simple union.

@typeholes

Copy link
Copy Markdown
Author

fixes #58376

@ehoogeveen-medweb

Emanuel Hoogeveen (ehoogeveen-medweb) commented Apr 30, 2024

Copy link
Copy Markdown

Does this also need some sort of handling for objects with symbol type keys? Properties with such keys won't be returned, but Object.values() and Object.entries() should still accept such objects.

@typeholes

Copy link
Copy Markdown
Author

Does this also need some sort of handling for objects with symbol type keys? Properties with such keys won't be returned, but Object.values() and Object.entries() should still accept such objects.

There is already an overload for values and entries, so they will be accepted.
for example, values(o: {}): any[]; Of course the any[] return type is not ideal, but I'm not sure anything else is workable for the fallback.

@ehoogeveen-medweb

Copy link
Copy Markdown

Thanks, I didn't look beyond the context of the diff :)

Locally I use something like this:

typeKeyToString<Kextendsnumber|string|symbol>=Kextendsstring ? K : Kextendsnumber ? `${K}` : never;keys<Kextendsnumber|string|symbol,V>(o: Record<K,V>): KeyToString<K>[];entries<Kextendsnumber|string|symbol,V>(o: Record<K,V>): [KeyToString<K>,V][];values<Kextendsnumber|string|symbol,V>(o: Record<K,V>): V[];

but aside from being too complex for the standard library, that probably opens up a whole can of worms if applied to everything (works well for my code though!).

@microsoftMicrosoft (microsoft) locked as resolved and limited conversation to collaborators Oct 16, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

For Uncommitted BugPR for untriaged, rejected, closed or missing bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Object.values and Object.entries return type any when passing an object defined as having number keys

5 participants

@typeholes@jakebailey@typescript-bot@ehoogeveen-medweb@sandersn