Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add numeric constraints to type parameters of mapped types with array/tuple intersections constraints #60084

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Andarist
Copy link
Contributor

this, I feel, is something that was missed in #57801

Given this code:

type MustBeArray<T extends any[]> = T;

type MustHaveFooBar<T extends { foo: unknown; bar: unknown }> = T;

type Hmm2<T> = T extends { foo: string }[]
  ? T extends { bar: number }[]
    ? MustBeArray<{ [I in keyof T]: MustHaveFooBar<T[I]> }>
    : never
  : never;

The apparent type of this mapped type is ({ bar: number; } & { foo: string; })[] (since #57801 ). So it only makes sense to treat T[I] as access with this numeric constraint for I. In other words, it only makes sense to treat T[I] as accessing an element of an array/tuple

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Sep 27, 2024
@typescript-bot
Copy link
Collaborator

This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise.

@jakebailey
Copy link
Member

@typescript-bot test it

@typescript-bot
Copy link
Collaborator

typescript-bot commented Sep 27, 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

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 Here are the results of running the user tests with tsc comparing main and refs/pull/60084/merge:

Everything looks good!

@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,378 50,378 ~ ~ ~ p=1.000 n=6
Memory used 193,987k (± 0.93%) 192,735k (± 0.01%) ~ 192,706k 192,762k p=0.054 n=6
Parse Time 1.32s (± 0.75%) 1.32s (± 0.64%) ~ 1.30s 1.32s p=0.445 n=6
Bind Time 0.72s 0.72s (± 0.57%) ~ 0.72s 0.73s p=0.405 n=6
Check Time 9.74s (± 0.46%) 9.74s (± 0.19%) ~ 9.72s 9.77s p=0.936 n=6
Emit Time 2.72s (± 0.63%) 2.73s (± 0.49%) ~ 2.71s 2.75s p=0.366 n=6
Total Time 14.50s (± 0.35%) 14.50s (± 0.16%) ~ 14.46s 14.52s p=0.935 n=6
angular-1 - node (v18.15.0, x64)
Errors 7 7 ~ ~ ~ p=1.000 n=6
Symbols 947,102 947,102 ~ ~ ~ p=1.000 n=6
Types 410,738 410,995 +257 (+ 0.06%) ~ ~ p=0.001 n=6
Memory used 1,224,083k (± 0.00%) 1,224,135k (± 0.01%) ~ 1,224,073k 1,224,226k p=0.128 n=6
Parse Time 6.62s (± 0.39%) 6.63s (± 0.79%) ~ 6.58s 6.73s p=1.000 n=6
Bind Time 1.88s (± 0.27%) 1.88s (± 0.62%) ~ 1.86s 1.89s p=0.929 n=6
Check Time 31.76s (± 0.22%) 31.74s (± 0.54%) ~ 31.55s 31.95s p=0.936 n=6
Emit Time 15.13s (± 0.27%) 15.16s (± 0.44%) ~ 15.09s 15.28s p=0.629 n=6
Total Time 55.40s (± 0.14%) 55.41s (± 0.37%) ~ 55.12s 55.68s p=0.936 n=6
mui-docs - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 2,521,651 2,521,651 ~ ~ ~ p=1.000 n=6
Types 936,037 936,038 +1 (+ 0.00%) ~ ~ p=0.001 n=6
Memory used 2,351,704k (± 0.00%) 2,351,754k (± 0.00%) +51k (+ 0.00%) 2,351,687k 2,351,808k p=0.045 n=6
Parse Time 9.32s (± 0.31%) 9.32s (± 0.34%) ~ 9.26s 9.35s p=0.627 n=6
Bind Time 2.15s (± 0.39%) 2.16s (± 0.59%) ~ 2.14s 2.18s p=0.352 n=6
Check Time 75.96s (± 0.44%) 75.86s (± 0.44%) ~ 75.42s 76.19s p=0.689 n=6
Emit Time 0.28s (± 1.45%) 0.28s (± 1.86%) ~ 0.27s 0.28s p=0.114 n=6
Total Time 87.72s (± 0.36%) 87.62s (± 0.40%) ~ 87.18s 87.96s p=0.936 n=6
self-build-src - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 1,250,668 1,250,670 +2 (+ 0.00%) ~ ~ p=0.001 n=6
Types 265,081 265,082 +1 (+ 0.00%) ~ ~ p=0.001 n=6
Memory used 2,406,078k (± 0.03%) 2,406,458k (± 0.02%) ~ 2,405,857k 2,407,020k p=0.298 n=6
Parse Time 5.18s (± 1.13%) 5.21s (± 1.05%) ~ 5.12s 5.28s p=0.230 n=6
Bind Time 1.97s (± 0.59%) 1.97s (± 0.38%) ~ 1.96s 1.98s p=0.734 n=6
Check Time 35.56s (± 0.19%) 35.56s (± 0.58%) ~ 35.24s 35.84s p=0.688 n=6
Emit Time 3.00s (± 2.13%) 3.04s (± 3.86%) ~ 2.96s 3.27s p=0.936 n=6
Total Time 45.73s (± 0.27%) 45.77s (± 0.68%) ~ 45.43s 46.34s p=1.000 n=6
self-build-src-public-api - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 1,250,668 1,250,670 +2 (+ 0.00%) ~ ~ p=0.001 n=6
Types 265,081 265,082 +1 (+ 0.00%) ~ ~ p=0.001 n=6
Memory used 2,636,919k (±10.47%) 2,747,595k (±12.80%) ~ 2,485,047k 3,201,574k p=0.936 n=6
Parse Time 6.67s (± 1.98%) 6.73s (± 2.66%) ~ 6.56s 7.03s p=0.872 n=6
Bind Time 2.13s (± 0.71%) 2.17s (± 1.77%) ~ 2.11s 2.22s p=0.108 n=6
Check Time 42.97s (± 0.30%) 42.98s (± 0.28%) ~ 42.81s 43.14s p=1.000 n=6
Emit Time 3.33s (± 1.75%) 3.31s (± 2.46%) ~ 3.17s 3.39s p=0.936 n=6
Total Time 55.13s (± 0.37%) 55.19s (± 0.24%) ~ 54.96s 55.34s p=0.936 n=6
self-compiler - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 260,987 260,989 +2 (+ 0.00%) ~ ~ p=0.001 n=6
Types 106,423 106,424 +1 (+ 0.00%) ~ ~ p=0.001 n=6
Memory used 436,854k (± 0.01%) 436,861k (± 0.01%) ~ 436,771k 436,937k p=0.575 n=6
Parse Time 3.52s (± 0.91%) 3.51s (± 0.53%) ~ 3.48s 3.53s p=1.000 n=6
Bind Time 1.30s (± 2.25%) 1.30s (± 1.81%) ~ 1.27s 1.33s p=0.747 n=6
Check Time 18.89s (± 0.33%) 18.92s (± 0.39%) ~ 18.82s 18.99s p=0.258 n=6
Emit Time 1.48s (± 0.43%) 1.48s (± 1.26%) ~ 1.45s 1.50s p=1.000 n=6
Total Time 25.19s (± 0.33%) 25.21s (± 0.31%) ~ 25.09s 25.29s p=0.688 n=6
ts-pre-modules - node (v18.15.0, x64)
Errors 68 68 ~ ~ ~ p=1.000 n=6
Symbols 225,916 225,916 ~ ~ ~ p=1.000 n=6
Types 94,414 94,414 ~ ~ ~ p=1.000 n=6
Memory used 370,953k (± 0.02%) 370,965k (± 0.01%) ~ 370,902k 371,011k p=0.575 n=6
Parse Time 2.88s (± 1.11%) 2.92s (± 0.52%) ~ 2.90s 2.94s p=0.073 n=6
Bind Time 1.57s (± 1.23%) 1.59s (± 2.06%) ~ 1.55s 1.64s p=0.418 n=6
Check Time 16.29s (± 0.42%) 16.33s (± 0.34%) ~ 16.23s 16.38s p=0.421 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 20.75s (± 0.29%) 20.83s (± 0.22%) +0.08s (+ 0.40%) 20.77s 20.89s p=0.045 n=6
vscode - node (v18.15.0, x64)
Errors 1 1 ~ ~ ~ p=1.000 n=6
Symbols 3,106,060 3,106,060 ~ ~ ~ p=1.000 n=6
Types 1,071,136 1,071,136 ~ ~ ~ p=1.000 n=6
Memory used 3,200,679k (± 0.00%) 3,200,662k (± 0.00%) ~ 3,200,542k 3,200,767k p=1.000 n=6
Parse Time 14.01s (± 0.26%) 14.01s (± 0.72%) ~ 13.92s 14.21s p=0.420 n=6
Bind Time 4.46s (± 2.50%) 4.74s (±16.89%) ~ 4.39s 6.38s p=1.000 n=6
Check Time 86.80s (± 2.86%) 84.73s (± 2.51%) ~ 81.71s 88.38s p=0.093 n=6
Emit Time 24.58s (± 9.72%) 23.13s (± 7.81%) ~ 22.28s 26.82s p=0.378 n=6
Total Time 129.85s (± 3.57%) 126.62s (± 1.45%) ~ 125.25s 129.11s p=0.128 n=6
webpack - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 279,071 279,071 ~ ~ ~ p=1.000 n=6
Types 113,893 113,893 ~ ~ ~ p=1.000 n=6
Memory used 428,807k (± 0.03%) 428,841k (± 0.04%) ~ 428,565k 429,088k p=0.936 n=6
Parse Time 4.06s (± 1.12%) 4.04s (± 0.75%) ~ 3.99s 4.08s p=0.376 n=6
Bind Time 1.74s (± 1.05%) 1.74s (± 1.58%) ~ 1.71s 1.77s p=1.000 n=6
Check Time 18.05s (± 0.67%) 18.22s (± 0.81%) ~ 17.99s 18.38s p=0.093 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 23.86s (± 0.60%) 24.00s (± 0.67%) ~ 23.78s 24.21s p=0.090 n=6
xstate-main - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 540,027 540,027 ~ ~ ~ p=1.000 n=6
Types 181,292 181,296 +4 (+ 0.00%) ~ ~ p=0.001 n=6
Memory used 483,617k (± 0.04%) 483,582k (± 0.03%) ~ 483,325k 483,712k p=0.689 n=6
Parse Time 3.36s (± 0.69%) 3.36s (± 1.16%) ~ 3.29s 3.41s p=1.000 n=6
Bind Time 1.17s (± 1.26%) 1.17s (± 0.89%) ~ 1.16s 1.19s p=0.805 n=6
Check Time 18.97s (± 1.26%) 18.98s (± 1.11%) ~ 18.87s 19.41s p=1.000 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 23.50s (± 1.07%) 23.51s (± 0.98%) ~ 23.33s 23.97s p=0.936 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/60084/merge:

Something interesting changed - please have a look.

Details

vuejs/core

4 of 6 projects failed to build with the old tsc and were ignored

tsconfig.json

@jakebailey
Copy link
Member

Curious how this has the same vue change as #55386

@Andarist
Copy link
Contributor Author

It happens to behave in the same way because the created substitution type has .constraint that is an array/tuple type. In
#55386 getConstraintOfTypeParameter lucked out by reading that property, thinking it reads it from a type parameter but it was reading it from a substation type.

This PR here ends up reading similar information but this time through correct functions. In the case of the substation type getConstraintOfType ends up calling getBaseConstraintOfType.

However, this still boils down to an existing issue: #59260

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
Status: Not started
Development

Successfully merging this pull request may close these issues.

3 participants