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

Fix support for intersections in template literal placeholder types #56434

Merged
merged 6 commits into from Nov 21, 2023

Conversation

ahejlsberg
Copy link
Member

Implements the changes discussed here and fixes #54177 according to our design meeting discussion.

Fixes #54177.

@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 Nov 16, 2023

Heya @ahejlsberg, I've started to run the tsc-only perf test suite on this PR at ca7e9c4. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Nov 16, 2023

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

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Nov 16, 2023

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

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Nov 16, 2023

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

Update: The results are in!

@typescript-bot
Copy link
Collaborator

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

Here they are:

Compiler

Comparison Report - baseline..pr
Metric baseline pr Delta Best Worst p-value
Angular - node (v18.15.0, x64)
Memory used 295,199k (± 0.01%) 295,206k (± 0.01%) ~ 295,164k 295,243k p=0.688 n=6
Parse Time 2.64s (± 0.20%) 2.64s (± 0.24%) ~ 2.63s 2.65s p=0.386 n=6
Bind Time 0.83s (± 0.76%) 0.82s (± 0.00%) -0.01s (- 1.20%) 0.82s 0.82s p=0.008 n=6
Check Time 8.04s (± 0.25%) 8.04s (± 0.27%) ~ 8.01s 8.07s p=0.807 n=6
Emit Time 7.05s (± 0.07%) 7.08s (± 0.18%) +0.03s (+ 0.38%) 7.06s 7.09s p=0.006 n=6
Total Time 18.57s (± 0.10%) 18.58s (± 0.07%) ~ 18.56s 18.60s p=0.504 n=6
Compiler-Unions - node (v18.15.0, x64)
Memory used 191,704k (± 1.28%) 194,049k (± 1.47%) ~ 190,708k 196,557k p=0.128 n=6
Parse Time 1.35s (± 0.38%) 1.37s (± 0.72%) +0.01s (+ 1.11%) 1.35s 1.38s p=0.022 n=6
Bind Time 0.72s (± 0.00%) 0.72s (± 0.00%) ~ 0.72s 0.72s p=1.000 n=6
Check Time 9.17s (± 0.36%) 9.17s (± 0.33%) ~ 9.11s 9.20s p=0.872 n=6
Emit Time 2.64s (± 0.29%) 2.65s (± 0.57%) ~ 2.62s 2.66s p=0.316 n=6
Total Time 13.88s (± 0.28%) 13.89s (± 0.20%) ~ 13.85s 13.93s p=0.747 n=6
Monaco - node (v18.15.0, x64)
Memory used 347,341k (± 0.00%) 347,353k (± 0.01%) ~ 347,315k 347,383k p=0.378 n=6
Parse Time 2.45s (± 0.80%) 2.45s (± 0.49%) ~ 2.43s 2.46s p=1.000 n=6
Bind Time 0.93s (± 0.44%) 0.93s (± 0.56%) ~ 0.92s 0.93s p=0.595 n=6
Check Time 6.92s (± 0.45%) 6.91s (± 0.11%) ~ 6.90s 6.92s p=0.464 n=6
Emit Time 4.04s (± 0.56%) 4.05s (± 0.25%) ~ 4.04s 4.06s p=0.360 n=6
Total Time 14.34s (± 0.31%) 14.34s (± 0.20%) ~ 14.30s 14.38s p=0.871 n=6
TFS - node (v18.15.0, x64)
Memory used 302,631k (± 0.01%) 302,622k (± 0.01%) ~ 302,604k 302,646k p=1.000 n=6
Parse Time 1.99s (± 1.13%) 1.98s (± 1.27%) ~ 1.94s 2.01s p=0.220 n=6
Bind Time 1.00s (± 1.22%) 1.00s (± 0.52%) ~ 0.99s 1.00s p=0.241 n=6
Check Time 6.27s (± 0.56%) 6.29s (± 0.70%) ~ 6.21s 6.33s p=0.374 n=6
Emit Time 3.58s (± 0.42%) 3.58s (± 0.46%) ~ 3.56s 3.60s p=0.510 n=6
Total Time 12.85s (± 0.43%) 12.84s (± 0.43%) ~ 12.74s 12.89s p=0.936 n=6
material-ui - node (v18.15.0, x64)
Memory used 470,572k (± 0.01%) 470,544k (± 0.01%) ~ 470,514k 470,582k p=0.173 n=6
Parse Time 2.57s (± 0.67%) 2.57s (± 0.52%) ~ 2.55s 2.58s p=0.739 n=6
Bind Time 0.99s (± 1.23%) 0.99s (± 0.52%) ~ 0.98s 0.99s p=1.000 n=6
Check Time 16.62s (± 0.38%) 16.61s (± 0.16%) ~ 16.56s 16.63s 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.18s (± 0.37%) 20.17s (± 0.13%) ~ 20.12s 20.19s p=0.935 n=6
xstate - node (v18.15.0, x64)
Memory used 512,872k (± 0.01%) 512,819k (± 0.01%) ~ 512,760k 512,872k p=0.199 n=6
Parse Time 3.27s (± 0.49%) 3.27s (± 0.30%) ~ 3.26s 3.28s p=0.720 n=6
Bind Time 1.54s (± 0.49%) 1.54s (± 0.53%) ~ 1.53s 1.55s p=0.729 n=6
Check Time 2.85s (± 0.34%) 2.86s (± 0.60%) ~ 2.83s 2.88s p=0.250 n=6
Emit Time 0.08s (± 0.00%) 0.08s (± 0.00%) ~ 0.08s 0.08s p=1.000 n=6
Total Time 7.73s (± 0.29%) 7.75s (± 0.32%) ~ 7.72s 7.78s p=0.145 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)
  • xstate - node (v18.15.0, x64)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

Developer Information:

Download Benchmarks

@typescript-bot
Copy link
Collaborator

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

There were infrastructure failures potentially unrelated to your change:

  • 2 instances 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

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/56434/merge:

Everything looks good!

@DanielRosenwasser
Copy link
Member

@typescript-bot pack this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Nov 17, 2023

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Nov 17, 2023

Hey @DanielRosenwasser, 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/158671/artifacts?artifactName=tgz&fileId=DBC66C962627F09CAB1254DBD4AC2876AD0FE6754317E0AF108CDAF61D2D957D02&fileName=/typescript-5.4.0-insiders.20231117.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-56434-11".;

@ahejlsberg
Copy link
Member Author

ahejlsberg commented Nov 17, 2023

@jakebailey @DanielRosenwasser So, there's this beauty:

type Goo<T> = {
  [key: `abc${"def" & { tag: T }}`]: string;
}

type T0 = Goo<void>;  // Index signature key type not instantiated so type parameter leaks

By design we don't instantiate index signature key types (that's what mapped types are for), but that in turn means we really can't permit anything generic in tag types. But we have no guaranteed way of detecting whether an object type contains something generic. I should say that there's nothing particularly dangerous about the leaked type parameter (it's just a type that isn't compatible with anything but itself), but it's certainly esthetically displeasing.

Starting to seem like we just want to strip tags in template literal placeholders.

@ahejlsberg
Copy link
Member Author

ahejlsberg commented Nov 18, 2023

Hmm, the leaking type parameter issue isn't actually anything new:

type Leak<T> = {
  [key: string & { tag: T }]: string;
}

type T0 = Leak<void>;  // Index signature key type not instantiated so type parameter leaks

I seem to recall us discussing this at some point in the past but can't find anything. As I said above, it's harmless, but certainly doesn't look right.

@ahejlsberg ahejlsberg merged commit c266e47 into main Nov 21, 2023
19 checks passed
@ahejlsberg ahejlsberg deleted the fixPlaceholderIntersections branch November 21, 2023 01:09
@DanielRosenwasser
Copy link
Member

@typescript-bot cherry-pick this to release-5.3

@typescript-bot
Copy link
Collaborator

typescript-bot commented Nov 21, 2023

Heya @DanielRosenwasser, I've started to run the task to cherry-pick this into release-5.3 on this PR at b464619. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

Hey @DanielRosenwasser, I've opened #56491 for you.

typescript-bot pushed a commit to typescript-bot/TypeScript that referenced this pull request Nov 21, 2023
Component commits:
7fa9179 Fix support for intersections in template literal placeholder types

f45b6dd Accept new baselines

2cf8379 Update test

ca7e9c4 Accept new baselines

8ab01eb Update fourslash test

b464619 Add more tests per code review
DanielRosenwasser pushed a commit that referenced this pull request Nov 30, 2023
…e-5.3 (#56491)

Co-authored-by: Anders Hejlsberg <andersh@microsoft.com>
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
None yet
Development

Successfully merging this pull request may close these issues.

Template Literal Types reduces string union
5 participants