Conversation

ahejlsberg

Fixes #46045.
Fixes #46125.


// Repro from #46045

export type Action =
Copy link
Member

Choose a reason for hiding this comment

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

We probably want to remove the export from this and the other line to keep around the declaration emit in the test.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, for sure.

const targetEnd = target.texts[target.texts.length - 1];
const startLen = Math.min(sourceStart.length, targetStart.length);
const endLen = Math.min(sourceEnd.length, targetEnd.length);
return sourceStart.slice(0, startLen) !== targetStart.slice(0, startLen) ||
Copy link
Member

Choose a reason for hiding this comment

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

Won't this flag foo-${boolean} and foo-${number} as possibly related? We still need to make sure the holes relate when this returns True, no?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it'll flag them as possibly related. Or, rather, not flag them as definitely unrelated. We could potentially check the placeholders that immediately follow identical prefix texts or immediately precede identical suffix texts, but honestly there's very little gained from it. In fact, probably only the boolean vs. number disqualification. I think what is here already is sufficient, and it impacts whether we flag operands as non-overlapping, which isn't super critical to get 100% right.


// Repro from #46125

function ff1<T extends string>(x: `foo-${string}`, y: `${string}-bar`, z: `baz-${string}`) {
Copy link
Member

Choose a reason for hiding this comment

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

Before I forget, can we also get a copy of this test with a signature like

function ff1<T extends string>(x: `foo-${T}`, y: `${T}-bar`, z: `baz-${T}`) {

? I figure it should behave the same, but, y'know, coverage. Maybe it can just be more cases on this signature, since it already has a generic parameter for some reason~

Copy link
Member Author

Choose a reason for hiding this comment

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

Will do.

@DanielRosenwasser

@typescript-bot test this
@typescript-bot user test this
@typescript-bot perf test this

@typescript-bot

Heya @DanielRosenwasser, I've started to run the perf test suite on this PR at e1907a2. You can monitor the build here.

Update: The results are in!

@typescript-bot

Heya @DanielRosenwasser, I've started to run the extended test suite on this PR at e1907a2. You can monitor the build here.

@typescript-bot

Heya @DanielRosenwasser, I've started to run the parallelized community code test suite on this PR at e1907a2. You can monitor the build here.

@typescript-bot

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

Here they are:

Comparison Report - main..46137

Metricmain46137DeltaBestWorst
Angular - node (v10.16.3, x64)
Memory used354,154k (± 0.02%)354,131k (± 0.02%)-23k (- 0.01%)354,015k354,332k
Parse Time1.94s (± 0.49%)1.94s (± 0.37%)+0.01s (+ 0.36%)1.93s1.96s
Bind Time0.84s (± 0.62%)0.84s (± 0.98%)+0.00s (+ 0.36%)0.83s0.86s
Check Time5.46s (± 0.46%)5.47s (± 0.50%)+0.00s (+ 0.07%)5.39s5.52s
Emit Time5.82s (± 0.33%)5.86s (± 0.69%)+0.04s (+ 0.67%)5.78s5.96s
Total Time14.06s (± 0.25%)14.12s (± 0.33%)+0.05s (+ 0.38%)14.01s14.23s
Compiler-Unions - node (v10.16.3, x64)
Memory used203,944k (± 0.02%)203,852k (± 0.04%)-91k (- 0.04%)203,701k203,992k
Parse Time0.78s (± 0.97%)0.79s (± 1.13%)+0.00s (+ 0.26%)0.77s0.81s
Bind Time0.52s (± 1.18%)0.52s (± 1.28%)+0.00s (+ 0.38%)0.51s0.54s
Check Time7.94s (± 0.70%)7.91s (± 0.57%)-0.02s (- 0.29%)7.82s8.06s
Emit Time2.47s (± 0.81%)2.46s (± 0.81%)-0.01s (- 0.45%)2.41s2.50s
Total Time11.71s (± 0.57%)11.68s (± 0.42%)-0.03s (- 0.26%)11.60s11.82s
Monaco - node (v10.16.3, x64)
Memory used342,054k (± 0.03%)341,996k (± 0.02%)-58k (- 0.02%)341,871k342,258k
Parse Time1.48s (± 0.51%)1.47s (± 0.71%)-0.01s (- 0.34%)1.44s1.49s
Bind Time0.75s (± 0.40%)0.75s (± 0.77%)-0.00s (- 0.27%)0.74s0.76s
Check Time5.45s (± 0.65%)5.44s (± 0.63%)-0.01s (- 0.17%)5.38s5.53s
Emit Time3.18s (± 0.69%)3.19s (± 0.96%)+0.00s (+ 0.13%)3.10s3.25s
Total Time10.86s (± 0.33%)10.85s (± 0.36%)-0.01s (- 0.11%)10.76s10.94s
TFS - node (v10.16.3, x64)
Memory used304,663k (± 0.02%)304,672k (± 0.02%)+9k (+ 0.00%)304,503k304,836k
Parse Time1.19s (± 0.50%)1.19s (± 0.44%)-0.00s (- 0.25%)1.18s1.20s
Bind Time0.71s (± 0.81%)0.71s (± 0.78%)-0.00s (- 0.28%)0.69s0.72s
Check Time4.99s (± 0.66%)4.96s (± 0.46%)-0.03s (- 0.56%)4.88s5.00s
Emit Time3.33s (± 1.65%)3.33s (± 0.88%)-0.01s (- 0.21%)3.26s3.40s
Total Time10.22s (± 0.61%)10.18s (± 0.42%)-0.04s (- 0.40%)10.05s10.26s
material-ui - node (v10.16.3, x64)
Memory used472,240k (± 0.02%)472,270k (± 0.02%)+30k (+ 0.01%)472,053k472,392k
Parse Time1.77s (± 0.38%)1.76s (± 0.50%)-0.00s (- 0.23%)1.75s1.79s
Bind Time0.66s (± 0.61%)0.66s (± 0.55%)-0.00s (- 0.46%)0.65s0.66s
Check Time14.41s (± 0.65%)14.38s (± 0.71%)-0.03s (- 0.18%)14.25s14.68s
Emit Time0.00s (± 0.00%)0.00s (± 0.00%)0.00s ( NaN%)0.00s0.00s
Total Time16.83s (± 0.59%)16.80s (± 0.64%)-0.03s (- 0.17%)16.66s17.12s
Angular - node (v12.1.0, x64)
Memory used332,038k (± 0.03%)331,993k (± 0.02%)-45k (- 0.01%)331,833k332,156k
Parse Time1.93s (± 0.78%)1.92s (± 0.45%)-0.00s (- 0.21%)1.90s1.93s
Bind Time0.82s (± 0.82%)0.81s (± 0.90%)-0.01s (- 0.61%)0.80s0.83s
Check Time5.30s (± 0.37%)5.30s (± 0.56%)-0.00s (- 0.06%)5.23s5.36s
Emit Time6.09s (± 0.61%)6.14s (± 0.89%)+0.04s (+ 0.72%)6.06s6.29s
Total Time14.14s (± 0.39%)14.18s (± 0.37%)+0.03s (+ 0.23%)14.03s14.30s
Compiler-Unions - node (v12.1.0, x64)
Memory used191,331k (± 0.11%)191,264k (± 0.12%)-66k (- 0.03%)190,408k191,506k
Parse Time0.78s (± 0.85%)0.78s (± 0.61%)-0.00s (- 0.38%)0.77s0.79s
Bind Time0.53s (± 0.98%)0.53s (± 0.92%)+0.00s (+ 0.95%)0.52s0.54s
Check Time7.43s (± 0.66%)7.39s (± 0.75%)-0.04s (- 0.54%)7.30s7.51s
Emit Time2.46s (± 1.03%)2.48s (± 0.95%)+0.02s (+ 0.69%)2.43s2.54s
Total Time11.20s (± 0.61%)11.18s (± 0.62%)-0.02s (- 0.21%)11.06s11.33s
Monaco - node (v12.1.0, x64)
Memory used325,116k (± 0.02%)325,088k (± 0.02%)-28k (- 0.01%)324,925k325,220k
Parse Time1.45s (± 0.47%)1.47s (± 0.81%)+0.01s (+ 0.89%)1.44s1.49s
Bind Time0.73s (± 0.47%)0.73s (± 1.06%)+0.00s (+ 0.55%)0.72s0.75s
Check Time5.35s (± 0.65%)5.31s (± 0.33%)-0.03s (- 0.58%)5.27s5.35s
Emit Time3.20s (± 0.70%)3.17s (± 0.65%)-0.03s (- 0.81%)3.14s3.22s
Total Time10.73s (± 0.46%)10.68s (± 0.36%)-0.04s (- 0.39%)10.60s10.77s
TFS - node (v12.1.0, x64)
Memory used289,416k (± 0.02%)289,429k (± 0.02%)+14k (+ 0.00%)289,295k289,617k
Parse Time1.21s (± 0.71%)1.21s (± 0.62%)+0.00s (+ 0.08%)1.20s1.23s
Bind Time0.69s (± 0.69%)0.69s (± 0.81%)+0.00s (+ 0.15%)0.68s0.70s
Check Time4.90s (± 0.26%)4.89s (± 0.31%)-0.02s (- 0.33%)4.86s4.94s
Emit Time3.39s (± 0.85%)3.38s (± 0.92%)-0.01s (- 0.35%)3.31s3.45s
Total Time10.20s (± 0.33%)10.17s (± 0.37%)-0.03s (- 0.25%)10.08s10.23s
material-ui - node (v12.1.0, x64)
Memory used450,955k (± 0.02%)450,742k (± 0.08%)-213k (- 0.05%)449,797k451,114k
Parse Time1.77s (± 0.47%)1.77s (± 0.57%)0.00s ( 0.00%)1.75s1.80s
Bind Time0.64s (± 1.32%)0.64s (± 1.25%)+0.00s (+ 0.16%)0.62s0.66s
Check Time13.05s (± 0.49%)13.00s (± 0.68%)-0.05s (- 0.38%)12.84s13.26s
Emit Time0.00s (± 0.00%)0.00s (± 0.00%)0.00s ( NaN%)0.00s0.00s
Total Time15.47s (± 0.45%)15.42s (± 0.58%)-0.05s (- 0.32%)15.26s15.67s
Angular - node (v14.15.1, x64)
Memory used330,452k (± 0.01%)330,452k (± 0.01%)-1k (- 0.00%)330,419k330,494k
Parse Time1.95s (± 0.67%)1.94s (± 0.49%)-0.00s (- 0.26%)1.93s1.97s
Bind Time0.86s (± 0.65%)0.86s (± 0.84%)+0.00s (+ 0.47%)0.85s0.88s
Check Time5.35s (± 0.56%)5.33s (± 0.58%)-0.02s (- 0.36%)5.26s5.40s
Emit Time6.22s (± 0.74%)6.20s (± 0.70%)-0.02s (- 0.32%)6.10s6.30s
Total Time14.38s (± 0.51%)14.33s (± 0.54%)-0.04s (- 0.29%)14.19s14.48s
Compiler-Unions - node (v14.15.1, x64)
Memory used193,187k (± 0.01%)192,529k (± 0.49%)-659k (- 0.34%)189,961k193,210k
Parse Time0.81s (± 0.64%)0.81s (± 0.90%)-0.00s (- 0.37%)0.80s0.83s
Bind Time0.56s (± 0.65%)0.55s (± 0.40%)-0.01s (- 0.90%)0.55s0.56s
Check Time7.55s (± 0.73%)7.49s (± 0.37%)-0.07s (- 0.86%)7.41s7.55s
Emit Time2.41s (± 0.48%)2.44s (± 1.14%)+0.04s (+ 1.45%)2.39s2.52s
Total Time11.32s (± 0.50%)11.29s (± 0.33%)-0.03s (- 0.26%)11.21s11.39s
Monaco - node (v14.15.1, x64)
Memory used323,989k (± 0.00%)323,996k (± 0.01%)+7k (+ 0.00%)323,956k324,046k
Parse Time1.51s (± 0.51%)1.51s (± 0.77%)-0.00s (- 0.20%)1.48s1.53s
Bind Time0.76s (± 0.48%)0.75s (± 0.79%)-0.00s (- 0.26%)0.74s0.77s
Check Time5.30s (± 0.59%)5.30s (± 0.49%)+0.00s (+ 0.02%)5.25s5.39s
Emit Time3.21s (± 0.87%)3.22s (± 0.81%)+0.02s (+ 0.50%)3.18s3.29s
Total Time10.78s (± 0.45%)10.79s (± 0.39%)+0.01s (+ 0.13%)10.69s10.89s
TFS - node (v14.15.1, x64)
Memory used288,334k (± 0.01%)288,337k (± 0.01%)+3k (+ 0.00%)288,294k288,407k
Parse Time1.24s (± 0.47%)1.23s (± 0.24%)-0.01s (- 0.73%)1.22s1.23s
Bind Time0.73s (± 0.84%)0.73s (± 0.55%)+0.00s (+ 0.00%)0.72s0.74s
Check Time4.91s (± 0.38%)4.93s (± 0.39%)+0.01s (+ 0.28%)4.88s4.97s
Emit Time3.48s (± 0.52%)3.49s (± 0.87%)+0.01s (+ 0.43%)3.43s3.56s
Total Time10.36s (± 0.25%)10.38s (± 0.31%)+0.02s (+ 0.19%)10.31s10.44s
material-ui - node (v14.15.1, x64)
Memory used448,958k (± 0.09%)449,300k (± 0.00%)+342k (+ 0.08%)449,275k449,351k
Parse Time1.82s (± 0.61%)1.81s (± 0.56%)-0.01s (- 0.49%)1.79s1.84s
Bind Time0.68s (± 1.03%)0.68s (± 0.69%)-0.00s (- 0.15%)0.67s0.69s
Check Time13.23s (± 1.18%)13.13s (± 0.55%)-0.10s (- 0.73%)12.97s13.36s
Emit Time0.00s (± 0.00%)0.00s (± 0.00%)0.00s ( NaN%)0.00s0.00s
Total Time15.73s (± 1.04%)15.63s (± 0.52%)-0.11s (- 0.67%)15.45s15.89s
System
Machine Namets-ci-ubuntu
Platformlinux 4.4.0-210-generic
Architecturex64
Available Memory16 GB
Available Memory8 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v10.16.3, x64)
  • node (v12.1.0, x64)
  • node (v14.15.1, x64)
Scenarios
  • Angular - node (v10.16.3, x64)
  • Angular - node (v12.1.0, x64)
  • Angular - node (v14.15.1, x64)
  • Compiler-Unions - node (v10.16.3, x64)
  • Compiler-Unions - node (v12.1.0, x64)
  • Compiler-Unions - node (v14.15.1, x64)
  • Monaco - node (v10.16.3, x64)
  • Monaco - node (v12.1.0, x64)
  • Monaco - node (v14.15.1, x64)
  • TFS - node (v10.16.3, x64)
  • TFS - node (v12.1.0, x64)
  • TFS - node (v14.15.1, x64)
  • material-ui - node (v10.16.3, x64)
  • material-ui - node (v12.1.0, x64)
  • material-ui - node (v14.15.1, x64)
BenchmarkNameIterations
Current4613710
Baselinemain10

Developer Information:

Download Benchmark

@typescript-bot

The user suite test run you requested has finished and failed. I've opened a PR with the baseline diff from master.

@ahejlsberg

Tests look clean, perf is slightly improved if anything. I think this one is good to go!

@zardoy

Great! But will buitin string methods support this? For now, I'm forced to use these standalone functions:

const startsWith = <T extends string>(str: string, search: T): str is `${T}${string}` => str.startsWith(search);
const endsWith = <T extends string>(str: string, search: T): str is `${string}${T}` => str.endsWith(search);
const includes = <T extends string>(str: string, search: T): str is `${string}${T}${string}` => str.includes(search);

Sign up for free to join this conversation on . Already have an account? Sign in to comment
Author: Team For Milestone BugPRs that fix a bug with a specific milestone
None yet

Successfully merging this pull request may close these issues.

Multiple issues with template literal type narrowing and relations Type narrowing on template literal types