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

Improve apparent type of mapped types #57122

Merged
merged 9 commits into from
Feb 19, 2024
Merged

Improve apparent type of mapped types #57122

merged 9 commits into from
Feb 19, 2024

Conversation

ahejlsberg
Copy link
Member

@ahejlsberg ahejlsberg commented Jan 22, 2024

This PR supersedes #56727 (which was reverted). The improvements in this PR don't exhibit the issue that caused us to revert #56727.

EDIT: However, the PR does break one test because the improved resolution of apparent types for mapped types causes the issue reported in #29919 to surface in that test.

I'm going to recommend we merge #50034, which fixes #29919 and thus the broken test in this PR.

Fixes #29919.
Fixes #56726.

@ahejlsberg
Copy link
Member Author

@typescript-bot test top100
@typescript-bot user test this
@typescript-bot run dt
@typescript-bot perf test this faster

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jan 22, 2024

Heya @ahejlsberg, I've started to run the parallelized Definitely Typed test suite on this PR at 14724a0. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jan 22, 2024

Heya @ahejlsberg, I've started to run the diff-based user code test suite on this PR at 14724a0. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jan 22, 2024

Heya @ahejlsberg, I've started to run the diff-based top-repos suite on this PR at 14724a0. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jan 22, 2024

Heya @ahejlsberg, I've started to run the faster perf test suite on this PR at 14724a0. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

@ahejlsberg Here are the results of running the user test suite comparing main and refs/pull/57122/merge:

There were infrastructure failures potentially unrelated to your change:

  • 1 instance of "Package install failed"

Otherwise...

Something interesting changed - please have a look.

Details

puppeteer

packages/browsers/test/src/tsconfig.json

@typescript-bot
Copy link
Collaborator

@ahejlsberg
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
Angular - node (v18.15.0, x64)
Memory used 295,658k (± 0.01%) 295,647k (± 0.01%) ~ 295,616k 295,664k p=0.688 n=6
Parse Time 2.67s (± 0.33%) 2.66s (± 0.34%) ~ 2.65s 2.67s p=0.113 n=6
Bind Time 0.83s (± 0.49%) 0.83s (± 1.32%) ~ 0.82s 0.85s p=1.000 n=6
Check Time 8.20s (± 0.21%) 8.19s (± 0.46%) ~ 8.14s 8.25s p=0.366 n=6
Emit Time 7.09s (± 0.16%) 7.10s (± 0.25%) ~ 7.08s 7.13s p=0.212 n=6
Total Time 18.78s (± 0.11%) 18.78s (± 0.23%) ~ 18.72s 18.84s p=0.872 n=6
Compiler-Unions - node (v18.15.0, x64)
Memory used 193,470k (± 1.54%) 192,513k (± 1.23%) ~ 191,509k 197,342k p=0.810 n=6
Parse Time 1.37s (± 1.22%) 1.36s (± 1.18%) ~ 1.34s 1.38s p=0.438 n=6
Bind Time 0.72s (± 0.00%) 0.72s (± 0.00%) ~ 0.72s 0.72s p=1.000 n=6
Check Time 9.36s (± 0.55%) 9.39s (± 0.37%) ~ 9.33s 9.42s p=0.464 n=6
Emit Time 2.62s (± 0.56%) 2.61s (± 0.70%) ~ 2.60s 2.64s p=0.601 n=6
Total Time 14.07s (± 0.31%) 14.08s (± 0.24%) ~ 14.03s 14.13s p=0.627 n=6
Monaco - node (v18.15.0, x64)
Memory used 347,451k (± 0.00%) 347,446k (± 0.00%) ~ 347,421k 347,463k p=0.630 n=6
Parse Time 2.48s (± 0.34%) 2.48s (± 0.74%) ~ 2.46s 2.50s p=0.566 n=6
Bind Time 0.93s (± 0.00%) 0.93s (± 0.56%) ~ 0.92s 0.93s p=0.174 n=6
Check Time 6.92s (± 0.31%) 6.94s (± 0.35%) ~ 6.92s 6.98s p=0.415 n=6
Emit Time 4.07s (± 0.88%) 4.05s (± 0.19%) ~ 4.04s 4.06s p=0.864 n=6
Total Time 14.40s (± 0.35%) 14.40s (± 0.28%) ~ 14.35s 14.46s p=0.872 n=6
TFS - node (v18.15.0, x64)
Memory used 302,836k (± 0.00%) 302,839k (± 0.01%) ~ 302,812k 302,898k p=0.936 n=6
Parse Time 2.03s (± 0.51%) 2.01s (± 0.96%) ~ 1.99s 2.04s p=0.190 n=6
Bind Time 1.00s (± 0.52%) 1.01s (± 0.88%) +0.01s (+ 1.34%) 1.00s 1.02s p=0.020 n=6
Check Time 6.34s (± 0.37%) 6.34s (± 0.40%) ~ 6.31s 6.37s p=0.746 n=6
Emit Time 3.61s (± 0.65%) 3.60s (± 0.80%) ~ 3.56s 3.64s p=1.000 n=6
Total Time 12.96s (± 0.24%) 12.97s (± 0.36%) ~ 12.91s 13.02s p=0.871 n=6
material-ui - node (v18.15.0, x64)
Memory used 511,284k (± 0.00%) 511,301k (± 0.01%) ~ 511,259k 511,338k p=0.470 n=6
Parse Time 2.65s (± 0.60%) 2.65s (± 0.62%) ~ 2.63s 2.67s p=0.934 n=6
Bind Time 0.99s (± 0.76%) 1.00s (± 1.17%) ~ 0.99s 1.02s p=0.383 n=6
Check Time 17.21s (± 0.32%) 17.21s (± 0.28%) ~ 17.12s 17.26s p=0.810 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 20.85s (± 0.27%) 20.86s (± 0.31%) ~ 20.73s 20.90s p=0.517 n=6
mui-docs - node (v18.15.0, x64)
Memory used 1,696,014k (± 0.00%) 1,695,540k (± 0.00%) -474k (- 0.03%) 1,695,501k 1,695,579k p=0.005 n=6
Parse Time 6.53s (± 0.26%) 6.55s (± 0.50%) ~ 6.51s 6.60s p=0.252 n=6
Bind Time 2.35s (± 0.50%) 2.35s (± 0.32%) ~ 2.34s 2.36s p=0.734 n=6
Check Time 55.36s (± 0.30%) 55.33s (± 0.35%) ~ 55.01s 55.57s p=0.936 n=6
Emit Time 0.16s (± 0.00%) 0.16s (± 0.00%) ~ 0.16s 0.16s p=1.000 n=6
Total Time 64.39s (± 0.27%) 64.39s (± 0.31%) ~ 64.06s 64.61s p=0.810 n=6
self-build-src - node (v18.15.0, x64)
Memory used 2,412,920k (± 0.04%) 2,412,952k (± 0.04%) ~ 2,412,045k 2,414,651k p=0.936 n=6
Parse Time 4.94s (± 0.88%) 4.95s (± 1.00%) ~ 4.90s 5.01s p=0.471 n=6
Bind Time 1.87s (± 0.89%) 1.87s (± 1.64%) ~ 1.83s 1.91s p=1.000 n=6
Check Time 33.44s (± 0.40%) 33.46s (± 0.26%) ~ 33.36s 33.56s p=0.810 n=6
Emit Time 2.67s (± 2.07%) 2.71s (± 1.34%) ~ 2.67s 2.77s p=0.297 n=6
Total Time 42.96s (± 0.42%) 43.02s (± 0.28%) ~ 42.87s 43.14s p=0.378 n=6
self-compiler - node (v18.15.0, x64)
Memory used 419,725k (± 0.01%) 419,729k (± 0.01%) ~ 419,699k 419,754k p=0.630 n=6
Parse Time 2.73s (± 3.81%) 2.75s (± 3.06%) ~ 2.66s 2.85s p=0.518 n=6
Bind Time 1.15s (± 7.04%) 1.15s (± 6.72%) ~ 1.07s 1.23s p=0.869 n=6
Check Time 15.10s (± 0.30%) 15.11s (± 0.21%) ~ 15.05s 15.14s p=0.808 n=6
Emit Time 1.16s (± 1.17%) 1.16s (± 1.92%) ~ 1.13s 1.19s p=0.744 n=6
Total Time 20.15s (± 0.18%) 20.16s (± 0.15%) ~ 20.12s 20.21s p=0.370 n=6
vscode - node (v18.15.0, x64)
Memory used 2,807,126k (± 0.00%) 2,807,124k (± 0.00%) ~ 2,807,029k 2,807,194k p=0.748 n=6
Parse Time 10.61s (± 0.32%) 10.63s (± 0.54%) ~ 10.54s 10.71s p=0.332 n=6
Bind Time 3.38s (± 0.47%) 3.38s (± 0.39%) ~ 3.37s 3.40s p=0.655 n=6
Check Time 59.81s (± 0.42%) 59.82s (± 0.51%) ~ 59.39s 60.13s p=0.936 n=6
Emit Time 16.14s (± 0.15%) 16.15s (± 0.50%) ~ 16.03s 16.26s p=0.630 n=6
Total Time 89.95s (± 0.26%) 89.99s (± 0.26%) ~ 89.58s 90.16s p=0.520 n=6
webpack - node (v18.15.0, x64)
Memory used 392,462k (± 0.02%) 392,452k (± 0.01%) ~ 392,411k 392,504k p=0.810 n=6
Parse Time 3.05s (± 1.39%) 3.04s (± 0.78%) ~ 3.00s 3.07s p=0.742 n=6
Bind Time 1.40s (± 0.70%) 1.40s (± 0.58%) ~ 1.39s 1.41s p=0.604 n=6
Check Time 13.95s (± 0.36%) 13.99s (± 0.32%) ~ 13.94s 14.05s p=0.172 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 18.39s (± 0.39%) 18.43s (± 0.29%) ~ 18.38s 18.51s p=0.297 n=6
xstate - node (v18.15.0, x64)
Memory used 513,403k (± 0.01%) 513,392k (± 0.01%) ~ 513,348k 513,429k p=0.298 n=6
Parse Time 3.28s (± 0.23%) 3.28s (± 0.43%) ~ 3.26s 3.30s p=0.867 n=6
Bind Time 1.54s (± 0.00%) 1.54s (± 0.33%) ~ 1.54s 1.55s p=0.174 n=6
Check Time 2.84s (± 0.47%) 2.85s (± 0.62%) ~ 2.82s 2.86s p=0.564 n=6
Emit Time 0.08s (± 4.99%) 0.08s (± 4.99%) ~ 0.08s 0.09s p=1.000 n=6
Total Time 7.75s (± 0.24%) 7.74s (± 0.31%) ~ 7.70s 7.77s p=0.607 n=6
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • Angular - node (v18.15.0, x64)
  • Compiler-Unions - node (v18.15.0, x64)
  • Monaco - node (v18.15.0, x64)
  • TFS - node (v18.15.0, x64)
  • material-ui - node (v18.15.0, x64)
  • mui-docs - node (v18.15.0, x64)
  • self-build-src - node (v18.15.0, x64)
  • self-compiler - node (v18.15.0, x64)
  • vscode - node (v18.15.0, x64)
  • webpack - node (v18.15.0, x64)
  • xstate - node (v18.15.0, x64)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

Developer Information:

Download Benchmarks

@typescript-bot
Copy link
Collaborator

Hey @ahejlsberg, the results of running the DT tests are ready.
Everything looks the same!
You can check the log here.

@typescript-bot
Copy link
Collaborator

@ahejlsberg Here are the results of running the top-repos suite comparing main and refs/pull/57122/merge:

Something interesting changed - please have a look.

Details

chakra-ui/chakra-ui

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

packages/components/tsconfig.build.json

  • error TS5056: Cannot write file '/mnt/ts_downloads/chakra-ui/packages/components/dist/types/menu/menu.stories.d.ts' because it would be overwritten by multiple input files.
    • Project Scope

const target = (type.target ?? type) as MappedType;
const typeVariable = getHomomorphicTypeVariable(target);
if (typeVariable && !target.declaration.nameType) {
const constraint = getConstraintTypeFromMappedType(type);
Copy link
Contributor

Choose a reason for hiding this comment

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

All of this makes sense now... it is tricky that mapped types don't have constraints resolvable by getBaseConstraintOfType and such but we can reach for getConstraintTypeFromMappedType and use that.

const typeVariable = getHomomorphicTypeVariable(target);
if (typeVariable && !target.declaration.nameType) {
const constraint = getConstraintTypeFromMappedType(type);
if (constraint.flags & TypeFlags.Index) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if this check shouldn't be replaced with an assert - it's quite a strong invariant that this branch can only be entered after getHomomorphicTypeVariable returns true and that requires the constraint to be an Index type.

Copy link
Member Author

Choose a reason for hiding this comment

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

An assert here wouldn't be right. There many cases where an instantiation of a homomorphic mapped type doesn't have a keyof XXX constraint anymore. For example, the homomorphic Readonly<T> has the constraint type keyof T, but the instantiation Readonly<{ a: string, b: string }> has the constraint type "a" | "b". What we're looking for here are instantiations where the constraint type is still a keyof XXX. That's what wasn't handled before.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for the explanation - it makes sense, getHomomorphicTypeVariable is called now with the target and not the type after all.

@Andarist
Copy link
Contributor

Andarist commented Jan 22, 2024

For what it's worth - I spent some sleepless nights on this last week so I built up some good context around this issue. LGTM (pending the resolution of #50034 ).

@gabritto
Copy link
Member

@typescript-bot pack this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jan 22, 2024

Heya @gabritto, I've started to run the tarball bundle task on this PR at 14724a0. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jan 22, 2024

Hey @gabritto, I've packed this into an installable tgz. You can install it for testing by referencing it in your package.json like so:

{
    "devDependencies": {
        "typescript": "https://typescript.visualstudio.com/cf7ac146-d525-443c-b23c-0d58337efebc/_apis/build/builds/159624/artifacts?artifactName=tgz&fileId=C49A8E55A05E919674BFB05C151C2461B3DCB587EA33BD5BEF7FADC7C7A5BDD802&fileName=/typescript-5.4.0-insiders.20240122.tgz"
    }
}

and then running npm install.


There is also a playground for this build and an npm module you can use via "typescript": "npm:@typescript-deploys/pr-build@5.4.0-pr-57122-12".;


type Curry<F extends ((...args: any) => any)> =
<T extends any[]>(...args: Tools.Cast<Tools.Cast<T, Gaps<Parameters<F>>>, any[]>) =>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Copy link
Member

Choose a reason for hiding this comment

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

How is the change in the PR causing this error?

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe the underlying issue is the same as it was in my PRs. This is now resolved through layers and thus getResolvedApparentTypeOfMappedType sees the constraint of Parameters<F> - that once gets computed as unknown[] (by getDefaultConstraintOfConditionalType when restrictive instantiation bails out from getConstraintOfDistributiveConditionalType) and once as any (by getConstraintOfDistributiveConditionalType). So any can get returned and getResolvedApparentTypeOfMappedType can't recognize this as an array-like. So it ends up not d about it not being assignable to readonly any[] (that is being checked to determine if the type can be used as rest).

IIRC the other case (when unknown[]) is returned makes any[] (added by this Cast) eliminated from the substitution type since, at that point, it's determined that the baseType satisfies the added constraint - so the baseType gets returned.

Copy link
Contributor

Choose a reason for hiding this comment

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

So the issue is mainly in the fact that previously the substitution type wasn't simplified at all here and that & any[] in it (coming from its added constraint) was preserved and made the comparison against readonly any[] OK.

Copy link
Member

Choose a reason for hiding this comment

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

What do you mean by "this is now resolved through layers"?
How do we go from a call to getResolvedApparentTypeOfMappedType to calls to getDefaultConstraintOfConditionalType and getConstraintOfDistributiveConditionalType?

Copy link
Contributor

Choose a reason for hiding this comment

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

Please note that I'm partially speaking based on what I remember about debugging this last week - so some details might be slightly off.

Gaps is a mapped type - so we enter getResolvedApparentTypeOfMappedType. With this PR we recognize that an instantiation of a homomorphic mapped type is received and we end up checking its constraint and if it's an index type. It turns out it is because it's something like keyof Parameters<...>. So we grab the .type and compute its base constraint. So now we are computing the constraint of a conditional type (through getConstraintFromConditionalType) and, as mentioned above, this once resolves through getDefaultConstraintOfConditionalType (for the restrictive instantiation case) and once through getConstraintOfDistributiveConditionalType (for a regular case :P).

Copy link
Member Author

Choose a reason for hiding this comment

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

With latest commit this error is gone.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Feb 16, 2024

Hey @gabritto, I've packed this into an installable tgz. You can install it for testing by referencing it in your package.json like so:

{
    "devDependencies": {
        "typescript": "https://typescript.visualstudio.com/cf7ac146-d525-443c-b23c-0d58337efebc/_apis/build/builds/159926/artifacts?artifactName=tgz&fileId=0CB616DD206446C008D255DF90ECB91D8A3A7FB7F44F73B0AD2F06AA1FE1696202&fileName=/typescript-5.4.0-insiders.20240216.tgz"
    }
}

and then running npm install.


There is also a playground for this build and an npm module you can use via "typescript": "npm:@typescript-deploys/pr-build@5.4.0-pr-57122-21".;

@typescript-bot
Copy link
Collaborator

Hey @ahejlsberg, the results of running the DT tests are ready.
There were interesting changes:

Branch only errors:

Package: lodash
Error:

Error: 
/home/vsts/work/1/DefinitelyTyped/types/lodash/common/function.d.ts
  1414:34  error  TypeScript@local compile error: 
Type '"0"' cannot be used to index type 'Parameters<T>'  @definitelytyped/expect
  1420:39  error  TypeScript@local compile error: 
Type '"0"' cannot be used to index type 'Parameters<T>'  @definitelytyped/expect

/home/vsts/work/1/DefinitelyTyped/types/lodash/common/util.d.ts
  313:71  error  TypeScript@local compile error: 
Type '"0"' cannot be used to index type 'Parameters<T>'  @definitelytyped/expect
  317:67  error  TypeScript@local compile error: 
Type '"0"' cannot be used to index type 'Parameters<T>'  @definitelytyped/expect
  321:63  error  TypeScript@local compile error: 
Type '"0"' cannot be used to index type 'Parameters<T>'  @definitelytyped/expect
  325:59  error  TypeScript@local compile error: 
Type '"0"' cannot be used to index type 'Parameters<T>'  @definitelytyped/expect
  329:55  error  TypeScript@local compile error: 
Type '"0"' cannot be used to index type 'Parameters<T>'  @definitelytyped/expect
  333:56  error  TypeScript@local compile error: 
Type '"0"' cannot be used to index type 'Parameters<T>'  @definitelytyped/expect
  343:71  error  TypeScript@local compile error: 
Type '"0"' cannot be used to index type 'Parameters<T>'  @definitelytyped/expect
  347:67  error  TypeScript@local compile error: 
Type '"0"' cannot be used to index type 'Parameters<T>'  @definitelytyped/expect
  351:63  error  TypeScript@local compile error: 
Type '"0"' cannot be used to index type 'Parameters<T>'  @definitelytyped/expect
  355:59  error  TypeScript@local compile error: 
Type '"0"' cannot be used to index type 'Parameters<T>'  @definitelytyped/expect
  359:55  error  TypeScript@local compile error: 
Type '"0"' cannot be used to index type 'Parameters<T>'  @definitelytyped/expect
  363:56  error  TypeScript@local compile error: 
Type '"0"' cannot be used to index type 'Parameters<T>'  @definitelytyped/expect

✖ 14 problems (14 errors, 0 warnings)

    at combineErrorsAndWarnings (/home/vsts/work/1/DefinitelyTyped/node_modules/.pnpm/@definitelytyped+dtslint@0.2.10_typescript@5.4.0-dev.20240216/node_modules/@definitelytyped/dtslint/dist/index.js:194:28)
    at runTests (/home/vsts/work/1/DefinitelyTyped/node_modules/.pnpm/@definitelytyped+dtslint@0.2.10_typescript@5.4.0-dev.20240216/node_modules/@definitelytyped/dtslint/dist/index.js:186:20)

You can check the log here.

@typescript-bot
Copy link
Collaborator

@ahejlsberg Here are the results of running the top-repos suite comparing main and refs/pull/57122/merge:

Something interesting changed - please have a look.

Details

ReactiveX/rxjs

11 of 15 projects failed to build with the old tsc and were ignored

packages/rxjs/src/tsconfig.types.json

vercel/hyper

2 of 3 projects failed to build with the old tsc and were ignored

tsconfig.json

  • error TS2536: Type '"0"' cannot be used to index type 'Parameters<T>'.
    • file:///mnt/ts_downloads/hyper/node_modules/@types/lodash/common/function.d.ts#L1414 in app/tsconfig.json
    • file:///mnt/ts_downloads/hyper/node_modules/@types/lodash/common/function.d.ts#L1420 in app/tsconfig.json
    • file:///mnt/ts_downloads/hyper/node_modules/@types/lodash/common/util.d.ts#L313 in app/tsconfig.json
    • file:///mnt/ts_downloads/hyper/node_modules/@types/lodash/common/util.d.ts#L317 in app/tsconfig.json
    • file:///mnt/ts_downloads/hyper/node_modules/@types/lodash/common/util.d.ts#L321 in app/tsconfig.json
    • file:///mnt/ts_downloads/hyper/node_modules/@types/lodash/common/util.d.ts#L325 in app/tsconfig.json
    • file:///mnt/ts_downloads/hyper/node_modules/@types/lodash/common/util.d.ts#L329 in app/tsconfig.json
    • file:///mnt/ts_downloads/hyper/node_modules/@types/lodash/common/util.d.ts#L333 in app/tsconfig.json
    • file:///mnt/ts_downloads/hyper/node_modules/@types/lodash/common/util.d.ts#L343 in app/tsconfig.json
    • file:///mnt/ts_downloads/hyper/node_modules/@types/lodash/common/util.d.ts#L347 in app/tsconfig.json
    • file:///mnt/ts_downloads/hyper/node_modules/@types/lodash/common/util.d.ts#L351 in app/tsconfig.json
    • file:///mnt/ts_downloads/hyper/node_modules/@types/lodash/common/util.d.ts#L355 in app/tsconfig.json
    • file:///mnt/ts_downloads/hyper/node_modules/@types/lodash/common/util.d.ts#L359 in app/tsconfig.json
    • file:///mnt/ts_downloads/hyper/node_modules/@types/lodash/common/util.d.ts#L363 in app/tsconfig.json

@ahejlsberg
Copy link
Member Author

The test runs reveal inconsistencies related to indexing arrays with numeric string literals (as in #50034):

function bar<T extends string[], K extends number>() {
    type T00 = string[]["0"];  // Ok
    type T01 = string[]["0.0"];  // Error, as expected
    type T02 = string[][K | "0"];  // Error, but shouldn't be
    type T10 = T["0"];  // Error, but shouldn't be
    type T11 = T["0.0"];  // Error, as expected
    type T12 = T[K | "0"];  // Error, but shouldn't be
}

The errors on T01 and T11 are expected because the numeric string literal doesn't round-trip (i.e. when converted to number and back to string, it yields a different representation). However, T02, T10, and T12 shouldn't error and I will fix that. Regardless of the fix, I don't think we want to include `${number}` in the index type for types that have a number index signature. First, it isn't quite correct because `${number}` doesn't require matching strings to round-trip, and second, it is a breaking change that I'd rather avoid. I think the best place to land is simply a targeted fix to make indexing with round-tripping numeric strings consistent as per the example above.

@typescript-bot typescript-bot added For Milestone Bug PRs that fix a bug with a specific milestone and removed For Backlog Bug PRs that fix a backlog bug labels Feb 18, 2024
@ahejlsberg
Copy link
Member Author

@typescript-bot test top100
@typescript-bot user test this
@typescript-bot run dt
@typescript-bot perf test this faster

@typescript-bot
Copy link
Collaborator

typescript-bot commented Feb 18, 2024

Heya @ahejlsberg, I've started to run the diff-based top-repos suite on this PR at 633bfc3. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Feb 18, 2024

Heya @ahejlsberg, I've started to run the parallelized Definitely Typed test suite on this PR at 633bfc3. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Feb 18, 2024

Heya @ahejlsberg, I've started to run the diff-based user code test suite on this PR at 633bfc3. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Feb 18, 2024

Heya @ahejlsberg, I've started to run the faster perf test suite on this PR at 633bfc3. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

@ahejlsberg Here are the results of running the user test suite comparing main and refs/pull/57122/merge:

There were infrastructure failures potentially unrelated to your change:

  • 1 instance of "Package install failed"

Otherwise...

Something interesting changed - please have a look.

Details

puppeteer

packages/browsers/test/src/tsconfig.json

@typescript-bot
Copy link
Collaborator

@ahejlsberg
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
Angular - node (v18.15.0, x64)
Memory used 295,653k (± 0.01%) 295,657k (± 0.01%) ~ 295,622k 295,690k p=1.000 n=6
Parse Time 2.66s (± 0.39%) 2.66s (± 0.37%) ~ 2.65s 2.67s p=0.452 n=6
Bind Time 0.84s (± 1.50%) 0.83s (± 0.91%) ~ 0.82s 0.84s p=0.115 n=6
Check Time 8.26s (± 0.24%) 8.25s (± 0.47%) ~ 8.19s 8.30s p=0.935 n=6
Emit Time 7.09s (± 0.26%) 7.10s (± 0.32%) ~ 7.07s 7.14s p=0.224 n=6
Total Time 18.85s (± 0.05%) 18.84s (± 0.29%) ~ 18.74s 18.89s p=0.936 n=6
Compiler-Unions - node (v18.15.0, x64)
Memory used 193,019k (± 1.28%) 193,517k (± 1.53%) ~ 191,576k 197,372k p=1.000 n=6
Parse Time 1.35s (± 0.81%) 1.37s (± 1.13%) +0.02s (+ 1.48%) 1.35s 1.38s p=0.034 n=6
Bind Time 0.72s (± 0.00%) 0.72s (± 0.00%) ~ 0.72s 0.72s p=1.000 n=6
Check Time 9.38s (± 0.50%) 9.41s (± 1.00%) ~ 9.32s 9.59s p=0.521 n=6
Emit Time 2.61s (± 0.45%) 2.61s (± 0.58%) ~ 2.59s 2.63s p=0.805 n=6
Total Time 14.06s (± 0.32%) 14.11s (± 0.70%) ~ 13.98s 14.28s p=0.293 n=6
Monaco - node (v18.15.0, x64)
Memory used 347,472k (± 0.01%) 347,470k (± 0.01%) ~ 347,447k 347,498k p=1.000 n=6
Parse Time 2.48s (± 0.33%) 2.48s (± 0.51%) ~ 2.46s 2.49s p=0.796 n=6
Bind Time 0.93s (± 0.81%) 0.93s (± 0.44%) ~ 0.92s 0.93s p=1.000 n=6
Check Time 6.95s (± 0.55%) 6.94s (± 0.28%) ~ 6.93s 6.98s p=0.686 n=6
Emit Time 4.04s (± 0.34%) 4.06s (± 0.34%) ~ 4.04s 4.08s p=0.241 n=6
Total Time 14.40s (± 0.24%) 14.40s (± 0.28%) ~ 14.35s 14.47s p=1.000 n=6
TFS - node (v18.15.0, x64)
Memory used 302,861k (± 0.01%) 302,881k (± 0.01%) ~ 302,856k 302,910k p=0.109 n=6
Parse Time 2.01s (± 0.92%) 2.01s (± 1.03%) ~ 1.98s 2.04s p=0.567 n=6
Bind Time 1.00s (± 1.03%) 1.00s (± 1.03%) ~ 0.99s 1.02s p=1.000 n=6
Check Time 6.36s (± 0.13%) 6.36s (± 0.17%) ~ 6.34s 6.37s p=0.652 n=6
Emit Time 3.59s (± 0.46%) 3.58s (± 0.53%) ~ 3.55s 3.60s p=0.804 n=6
Total Time 12.96s (± 0.18%) 12.95s (± 0.18%) ~ 12.92s 12.98s p=0.416 n=6
material-ui - node (v18.15.0, x64)
Memory used 511,275k (± 0.01%) 511,315k (± 0.01%) ~ 511,263k 511,467k p=0.378 n=6
Parse Time 2.66s (± 0.44%) 2.65s (± 0.81%) ~ 2.62s 2.67s p=0.315 n=6
Bind Time 0.99s (± 0.52%) 0.99s (± 0.90%) ~ 0.98s 1.00s p=0.541 n=6
Check Time 17.25s (± 0.47%) 17.27s (± 0.51%) ~ 17.16s 17.34s p=0.936 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 20.90s (± 0.35%) 20.91s (± 0.46%) ~ 20.77s 21.01s p=0.809 n=6
mui-docs - node (v18.15.0, x64)
Memory used 2,272,227k (± 0.00%) 2,271,775k (± 0.00%) -452k (- 0.02%) 2,271,749k 2,271,799k p=0.005 n=6
Parse Time 11.96s (± 0.77%) 12.04s (± 0.91%) ~ 11.88s 12.18s p=0.199 n=6
Bind Time 2.62s (± 0.29%) 2.62s (± 0.20%) ~ 2.62s 2.63s p=0.784 n=6
Check Time 102.63s (± 0.90%) 101.38s (± 0.85%) -1.25s (- 1.21%) 100.03s 102.42s p=0.045 n=6
Emit Time 0.32s (± 0.00%) 0.32s (± 1.27%) ~ 0.32s 0.33s p=0.405 n=6
Total Time 117.53s (± 0.83%) 116.37s (± 0.81%) ~ 114.87s 117.54s p=0.093 n=6
self-build-src - node (v18.15.0, x64)
Memory used 2,412,996k (± 0.02%) 2,413,466k (± 0.02%) ~ 2,412,685k 2,414,166k p=0.128 n=6
Parse Time 4.94s (± 1.21%) 4.94s (± 0.79%) ~ 4.89s 4.99s p=0.688 n=6
Bind Time 1.86s (± 0.65%) 1.88s (± 0.29%) +0.01s (+ 0.63%) 1.87s 1.88s p=0.038 n=6
Check Time 33.51s (± 0.28%) 33.52s (± 0.50%) ~ 33.30s 33.75s p=0.936 n=6
Emit Time 2.69s (± 1.54%) 2.66s (± 1.15%) ~ 2.63s 2.71s p=0.170 n=6
Total Time 43.03s (± 0.23%) 43.01s (± 0.43%) ~ 42.72s 43.24s p=0.936 n=6
self-compiler - node (v18.15.0, x64)
Memory used 418,843k (± 0.03%) 418,967k (± 0.01%) ~ 418,927k 419,004k p=0.066 n=6
Parse Time 2.80s (± 2.59%) 2.79s (± 2.21%) ~ 2.67s 2.84s p=0.514 n=6
Bind Time 1.10s (± 5.11%) 1.10s (± 5.27%) ~ 1.07s 1.22s p=0.445 n=6
Check Time 15.16s (± 0.31%) 15.21s (± 0.23%) ~ 15.16s 15.24s p=0.065 n=6
Emit Time 1.13s (± 0.91%) 1.14s (± 1.11%) ~ 1.13s 1.16s p=0.391 n=6
Total Time 20.19s (± 0.20%) 20.24s (± 0.21%) ~ 20.18s 20.30s p=0.127 n=6
vscode - node (v18.15.0, x64)
Memory used 2,844,942k (± 0.00%) 2,845,771k (± 0.00%) +829k (+ 0.03%) 2,845,731k 2,845,853k p=0.005 n=6
Parse Time 10.74s (± 0.39%) 10.75s (± 0.27%) ~ 10.72s 10.79s p=0.809 n=6
Bind Time 3.44s (± 0.37%) 3.43s (± 0.48%) ~ 3.41s 3.45s p=0.565 n=6
Check Time 60.39s (± 0.47%) 60.71s (± 0.49%) ~ 60.37s 61.18s p=0.093 n=6
Emit Time 16.35s (± 0.70%) 16.29s (± 0.57%) ~ 16.16s 16.44s p=0.377 n=6
Total Time 90.92s (± 0.23%) 91.18s (± 0.37%) ~ 90.79s 91.66s p=0.261 n=6
webpack - node (v18.15.0, x64)
Memory used 394,115k (± 0.02%) 394,202k (± 0.01%) ~ 394,159k 394,293k p=0.093 n=6
Parse Time 3.11s (± 0.47%) 3.12s (± 0.24%) ~ 3.11s 3.13s p=0.241 n=6
Bind Time 1.38s (± 0.92%) 1.39s (± 1.17%) ~ 1.37s 1.41s p=0.163 n=6
Check Time 14.09s (± 0.52%) 14.08s (± 0.32%) ~ 14.01s 14.13s p=0.872 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 18.58s (± 0.36%) 18.59s (± 0.31%) ~ 18.51s 18.67s p=0.872 n=6
xstate - node (v18.15.0, x64)
Memory used 513,356k (± 0.01%) 513,443k (± 0.02%) ~ 513,338k 513,650k p=0.128 n=6
Parse Time 3.27s (± 0.25%) 3.27s (± 0.32%) ~ 3.26s 3.29s p=0.932 n=6
Bind Time 1.54s (± 0.33%) 1.54s (± 0.49%) ~ 1.53s 1.55s p=0.784 n=6
Check Time 2.85s (± 0.87%) 2.87s (± 0.68%) ~ 2.85s 2.90s p=0.332 n=6
Emit Time 0.08s (± 4.99%) 0.08s (± 0.00%) ~ 0.08s 0.08s p=0.405 n=6
Total Time 7.76s (± 0.34%) 7.77s (± 0.27%) ~ 7.74s 7.80s p=0.517 n=6
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • Angular - node (v18.15.0, x64)
  • Compiler-Unions - node (v18.15.0, x64)
  • Monaco - node (v18.15.0, x64)
  • TFS - node (v18.15.0, x64)
  • material-ui - node (v18.15.0, x64)
  • mui-docs - node (v18.15.0, x64)
  • self-build-src - node (v18.15.0, x64)
  • self-compiler - node (v18.15.0, x64)
  • vscode - node (v18.15.0, x64)
  • webpack - node (v18.15.0, x64)
  • xstate - node (v18.15.0, x64)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

Developer Information:

Download Benchmarks

@typescript-bot
Copy link
Collaborator

Hey @ahejlsberg, the results of running the DT tests are ready.
Everything looks the same!
You can check the log here.

Comment on lines +16 to +23
function bar<T extends string[], K extends number>() {
type T00 = string[]["0"];
type T01 = string[]["0.0"]; // Error
type T02 = string[][K | "0"];
type T10 = T["0"];
type T11 = T["0.0"]; // Error
type T12 = T[K | "0"];
}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: those should likely be in a different test file since they don't have anything in common with this "test title" (assignmentToAnyArrayRestParameters)

@typescript-bot
Copy link
Collaborator

@ahejlsberg Here are the results of running the top-repos suite comparing main and refs/pull/57122/merge:

Everything looks good!

@ahejlsberg
Copy link
Member Author

Test and performance suites are all clean. This is ready to merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Milestone Bug PRs that fix a bug with a specific milestone
Projects
Archived in project
4 participants