Skip to content

Fix support for intersections in template literal placeholder types - #56434

Merged
Anders Hejlsberg (ahejlsberg) merged 6 commits into
mainfrom
fixPlaceholderIntersections
Nov 21, 2023
Merged

Fix support for intersections in template literal placeholder types#56434
Anders Hejlsberg (ahejlsberg) merged 6 commits into
mainfrom
fixPlaceholderIntersections

Conversation

@ahejlsberg

Copy link
Copy Markdown
Member

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

Fixes#54177.

@ahejlsberg

Copy link
Copy Markdown
MemberAuthor

@typescript-bot

TypeScript Bot (typescript-bot) commented Nov 16, 2023

Copy link
Copy Markdown
Contributor

Heya Anders Hejlsberg (@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

TypeScript Bot (typescript-bot) commented Nov 16, 2023

Copy link
Copy Markdown
Contributor

Heya Anders Hejlsberg (@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

TypeScript Bot (typescript-bot) commented Nov 16, 2023

Copy link
Copy Markdown
Contributor

Heya Anders Hejlsberg (@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

TypeScript Bot (typescript-bot) commented Nov 16, 2023

Copy link
Copy Markdown
Contributor

Heya Anders Hejlsberg (@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
Copy Markdown
Contributor

Anders Hejlsberg (@ahejlsberg)
The results of the perf run you requested are in!

Here they are:

Compiler

Comparison Report - baseline..pr
MetricbaselineprDeltaBestWorstp-value
Angular - node (v18.15.0, x64)
Memory used295,199k (± 0.01%)295,206k (± 0.01%)~295,164k295,243kp=0.688 n=6
Parse Time2.64s (± 0.20%)2.64s (± 0.24%)~2.63s2.65sp=0.386 n=6
Bind Time0.83s (± 0.76%)0.82s (± 0.00%)-0.01s (- 1.20%)0.82s0.82sp=0.008 n=6
Check Time8.04s (± 0.25%)8.04s (± 0.27%)~8.01s8.07sp=0.807 n=6
Emit Time7.05s (± 0.07%)7.08s (± 0.18%)+0.03s (+ 0.38%)7.06s7.09sp=0.006 n=6
Total Time18.57s (± 0.10%)18.58s (± 0.07%)~18.56s18.60sp=0.504 n=6
Compiler-Unions - node (v18.15.0, x64)
Memory used191,704k (± 1.28%)194,049k (± 1.47%)~190,708k196,557kp=0.128 n=6
Parse Time1.35s (± 0.38%)1.37s (± 0.72%)+0.01s (+ 1.11%)1.35s1.38sp=0.022 n=6
Bind Time0.72s (± 0.00%)0.72s (± 0.00%)~0.72s0.72sp=1.000 n=6
Check Time9.17s (± 0.36%)9.17s (± 0.33%)~9.11s9.20sp=0.872 n=6
Emit Time2.64s (± 0.29%)2.65s (± 0.57%)~2.62s2.66sp=0.316 n=6
Total Time13.88s (± 0.28%)13.89s (± 0.20%)~13.85s13.93sp=0.747 n=6
Monaco - node (v18.15.0, x64)
Memory used347,341k (± 0.00%)347,353k (± 0.01%)~347,315k347,383kp=0.378 n=6
Parse Time2.45s (± 0.80%)2.45s (± 0.49%)~2.43s2.46sp=1.000 n=6
Bind Time0.93s (± 0.44%)0.93s (± 0.56%)~0.92s0.93sp=0.595 n=6
Check Time6.92s (± 0.45%)6.91s (± 0.11%)~6.90s6.92sp=0.464 n=6
Emit Time4.04s (± 0.56%)4.05s (± 0.25%)~4.04s4.06sp=0.360 n=6
Total Time14.34s (± 0.31%)14.34s (± 0.20%)~14.30s14.38sp=0.871 n=6
TFS - node (v18.15.0, x64)
Memory used302,631k (± 0.01%)302,622k (± 0.01%)~302,604k302,646kp=1.000 n=6
Parse Time1.99s (± 1.13%)1.98s (± 1.27%)~1.94s2.01sp=0.220 n=6
Bind Time1.00s (± 1.22%)1.00s (± 0.52%)~0.99s1.00sp=0.241 n=6
Check Time6.27s (± 0.56%)6.29s (± 0.70%)~6.21s6.33sp=0.374 n=6
Emit Time3.58s (± 0.42%)3.58s (± 0.46%)~3.56s3.60sp=0.510 n=6
Total Time12.85s (± 0.43%)12.84s (± 0.43%)~12.74s12.89sp=0.936 n=6
material-ui - node (v18.15.0, x64)
Memory used470,572k (± 0.01%)470,544k (± 0.01%)~470,514k470,582kp=0.173 n=6
Parse Time2.57s (± 0.67%)2.57s (± 0.52%)~2.55s2.58sp=0.739 n=6
Bind Time0.99s (± 1.23%)0.99s (± 0.52%)~0.98s0.99sp=1.000 n=6
Check Time16.62s (± 0.38%)16.61s (± 0.16%)~16.56s16.63sp=0.936 n=6
Emit Time0.00s (± 0.00%)0.00s (± 0.00%)~0.00s0.00sp=1.000 n=6
Total Time20.18s (± 0.37%)20.17s (± 0.13%)~20.12s20.19sp=0.935 n=6
xstate - node (v18.15.0, x64)
Memory used512,872k (± 0.01%)512,819k (± 0.01%)~512,760k512,872kp=0.199 n=6
Parse Time3.27s (± 0.49%)3.27s (± 0.30%)~3.26s3.28sp=0.720 n=6
Bind Time1.54s (± 0.49%)1.54s (± 0.53%)~1.53s1.55sp=0.729 n=6
Check Time2.85s (± 0.34%)2.86s (± 0.60%)~2.83s2.88sp=0.250 n=6
Emit Time0.08s (± 0.00%)0.08s (± 0.00%)~0.08s0.08sp=1.000 n=6
Total Time7.73s (± 0.29%)7.75s (± 0.32%)~7.72s7.78sp=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)
BenchmarkNameIterations
Currentpr6
Baselinebaseline6

Developer Information:

Download Benchmarks

@typescript-bot

Copy link
Copy Markdown
Contributor

Anders Hejlsberg (@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
Copy Markdown
Contributor

Hey Anders Hejlsberg (@ahejlsberg), 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

Anders Hejlsberg (@ahejlsberg) Here are the results of running the top-repos suite comparing main and refs/pull/56434/merge:

Everything looks good!

@DanielRosenwasser

Copy link
Copy Markdown
Member

TypeScript Bot (@typescript-bot) pack this

@typescript-bot

TypeScript Bot (typescript-bot) commented Nov 17, 2023

Copy link
Copy Markdown
Contributor

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

@typescript-bot

TypeScript Bot (typescript-bot) commented Nov 17, 2023

Copy link
Copy Markdown
Contributor

Hey Daniel Rosenwasser (@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

Anders Hejlsberg (ahejlsberg) commented Nov 17, 2023

Copy link
Copy Markdown
MemberAuthor

Jake Bailey (@jakebailey)Daniel Rosenwasser (@DanielRosenwasser) So, there's this beauty:

typeGoo<T>={[key: `abc${"def"&{tag: T}}`]: string;}typeT0=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

Anders Hejlsberg (ahejlsberg) commented Nov 18, 2023

Copy link
Copy Markdown
MemberAuthor

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

typeLeak<T>={[key: string&{tag: T}]: string;}typeT0=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
Anders Hejlsberg (ahejlsberg) deleted the fixPlaceholderIntersections branch November 21, 2023 01:09
@DanielRosenwasser

Copy link
Copy Markdown
Member

TypeScript Bot (@typescript-bot) cherry-pick this to release-5.3

@typescript-bot

TypeScript Bot (typescript-bot) commented Nov 21, 2023

Copy link
Copy Markdown
Contributor

Heya Daniel Rosenwasser (@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
Copy Markdown
Contributor

Hey Daniel Rosenwasser (@DanielRosenwasser), I've opened #56491 for you.

TypeScript Bot (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
Daniel Rosenwasser (DanielRosenwasser) pushed a commit that referenced this pull request Nov 30, 2023
…e-5.3 (#56491)
Co-authored-by: Anders Hejlsberg <andersh@microsoft.com>
@jakebaileyJake Bailey (jakebailey) mentioned this pull request Mar 19, 2025
@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

Author: TeamFor Milestone BugPRs 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

@ahejlsberg@typescript-bot@DanielRosenwasser@jakebailey@Andarist