Skip to content

Reduce template literal types with a single placeholder and no extra texts - #55371

Merged
Gabriela Araujo Britto (gabritto) merged 6 commits into
microsoft:mainfrom
Andarist:fix/template-literal-type-with-no-texts-relations
Mar 14, 2024
Merged

Reduce template literal types with a single placeholder and no extra texts#55371
Gabriela Araujo Britto (gabritto) merged 6 commits into
microsoft:mainfrom
Andarist:fix/template-literal-type-with-no-texts-relations

Conversation

@Andarist

@AndaristMateusz Burzyński (Andarist) commented Aug 14, 2023

Copy link
Copy Markdown
Contributor

fixes#55364
fixes#56659

@typescript-botTypeScript Bot (typescript-bot) added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Aug 14, 2023
@Andarist
Mateusz Burzyński (Andarist)force-pushed the fix/template-literal-type-with-no-texts-relations branch from b6b579b to 12dbb98CompareAugust 14, 2023 17:34
@gabritto

This comment was marked as duplicate.

@gabritto

Copy link
Copy Markdown
Member

@typescript-bot

TypeScript Bot (typescript-bot) commented Aug 24, 2023

Copy link
Copy Markdown
Contributor

Heya Gabriela Araujo Britto (@gabritto), I've started to run the parallelized Definitely Typed test suite on this PR at d6fe15f. You can monitor the build here.

Update: The results are in!

@typescript-bot

TypeScript Bot (typescript-bot) commented Aug 24, 2023

Copy link
Copy Markdown
Contributor

Heya Gabriela Araujo Britto (@gabritto), I've started to run the diff-based user code test suite on this PR at d6fe15f. You can monitor the build here.

Update: The results are in!

@typescript-bot

TypeScript Bot (typescript-bot) commented Aug 24, 2023

Copy link
Copy Markdown
Contributor

Heya Gabriela Araujo Britto (@gabritto), I've started to run the regular perf test suite on this PR at d6fe15f. You can monitor the build here.

Update: The results are in!

@typescript-bot

TypeScript Bot (typescript-bot) commented Aug 24, 2023

Copy link
Copy Markdown
Contributor

Heya Gabriela Araujo Britto (@gabritto), I've started to run the diff-based top-repos suite on this PR at d6fe15f. You can monitor the build here.

Update: The results are in!

@typescript-bot

Copy link
Copy Markdown
Contributor

Gabriela Araujo Britto (@gabritto) Here are the results of running the user test suite comparing main and refs/pull/55371/merge:

There were infrastructure failures potentially unrelated to your change:

  • 1 instance of "Unknown failure"
  • 2 instances of "Package install failed"

Otherwise...

Something interesting changed - please have a look.

Details

rxjs-src

/mnt/ts_downloads/rxjs-src/build.sh

  • [NEW] error TS2428: All declarations of 'WeakMap' must have identical type parameters.
    • /home/vsts/work/1/s/typescript-55371/lib/lib.es2015.collection.d.ts(62,11)
    • /home/vsts/work/1/s/typescript-55371/lib/lib.es2015.iterable.d.ts(162,11)
    • /home/vsts/work/1/s/typescript-55371/lib/lib.es2015.symbol.wellknown.d.ts(140,11)
    • /home/vsts/work/1/s/typescript-55371/lib/lib.es2015.collection.d.ts(62,11)
    • /home/vsts/work/1/s/typescript-55371/lib/lib.es2015.iterable.d.ts(162,11)
    • /home/vsts/work/1/s/typescript-55371/lib/lib.es2015.symbol.wellknown.d.ts(140,11)
    • /home/vsts/work/1/s/typescript-55371/lib/lib.es2015.collection.d.ts(62,11)
    • /home/vsts/work/1/s/typescript-55371/lib/lib.es2015.iterable.d.ts(162,11)
    • /home/vsts/work/1/s/typescript-55371/lib/lib.es2015.symbol.wellknown.d.ts(140,11)
    • /home/vsts/work/1/s/typescript-55371/lib/lib.es2015.collection.d.ts(62,11)
    • /home/vsts/work/1/s/typescript-55371/lib/lib.es2015.iterable.d.ts(162,11)
    • /home/vsts/work/1/s/typescript-55371/lib/lib.es2015.symbol.wellknown.d.ts(140,11)
    • /home/vsts/work/1/s/typescript-55371/lib/lib.es2015.collection.d.ts(62,11)
    • /home/vsts/work/1/s/typescript-55371/lib/lib.es2015.iterable.d.ts(162,11)
    • /home/vsts/work/1/s/typescript-55371/lib/lib.es2015.symbol.wellknown.d.ts(140,11)
  • [MISSING] error TS2428: All declarations of 'WeakMap' must have identical type parameters.
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.collection.d.ts(62,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.iterable.d.ts(162,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.symbol.wellknown.d.ts(140,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.collection.d.ts(62,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.iterable.d.ts(162,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.symbol.wellknown.d.ts(140,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.collection.d.ts(62,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.iterable.d.ts(162,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.symbol.wellknown.d.ts(140,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.collection.d.ts(62,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.iterable.d.ts(162,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.symbol.wellknown.d.ts(140,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.collection.d.ts(62,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.iterable.d.ts(162,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.symbol.wellknown.d.ts(140,11)

Comment threadsrc/compiler/checker.ts Outdated
Comment threadsrc/compiler/checker.ts Outdated
@typescript-bot

Copy link
Copy Markdown
Contributor

Gabriela Araujo Britto (@gabritto)
The results of the perf run you requested are in!

Here they are:

Compiler

Comparison Report - baseline..pr
MetricbaselineprDeltaBestWorstp-value
Angular - node (v16.17.1, x64)
Memory used300,248k (± 0.01%)300,249k (± 0.01%)~300,219k300,269kp=0.936 n=6
Parse Time3.02s (± 0.18%)3.02s (± 0.00%)~3.02s3.02sp=0.071 n=6
Bind Time0.93s (± 0.00%)0.93s (± 0.00%)~0.93s0.93sp=1.000 n=6
Check Time9.28s (± 0.39%)9.30s (± 0.34%)~9.26s9.35sp=0.418 n=6
Emit Time7.63s (± 0.34%)7.64s (± 0.43%)~7.59s7.69sp=0.685 n=6
Total Time20.87s (± 0.25%)20.89s (± 0.20%)~20.84s20.94sp=0.421 n=6
Compiler-Unions - node (v16.17.1, x64)
Memory used194,483k (± 0.66%)193,976k (± 0.00%)~193,965k193,982kp=0.872 n=6
Parse Time1.58s (± 0.26%)1.58s (± 0.00%)~1.58s1.58sp=0.405 n=6
Bind Time0.80s (± 0.51%)0.80s (± 0.51%)~0.79s0.80sp=1.000 n=6
Check Time9.90s (± 0.42%)9.90s (± 0.14%)~9.88s9.92sp=0.628 n=6
Emit Time2.73s (± 0.20%)2.74s (± 0.31%)~2.72s2.74sp=0.855 n=6
Total Time15.02s (± 0.29%)15.01s (± 0.10%)~14.99s15.03sp=1.000 n=6
Monaco - node (v16.17.1, x64)
Memory used347,146k (± 0.00%)347,131k (± 0.01%)~347,091k347,169kp=0.936 n=6
Parse Time2.69s (± 0.31%)2.69s (± 0.15%)~2.69s2.70sp=0.097 n=6
Bind Time0.99s (± 0.00%)0.99s (± 0.52%)~0.99s1.00sp=0.174 n=6
Check Time7.91s (± 0.30%)7.91s (± 0.18%)~7.89s7.93sp=0.511 n=6
Emit Time4.27s (± 0.34%)4.26s (± 0.39%)~4.23s4.27sp=0.617 n=6
Total Time15.85s (± 0.11%)15.85s (± 0.15%)~15.82s15.88sp=0.570 n=6
TFS - node (v16.17.1, x64)
Memory used301,146k (± 0.00%)301,157k (± 0.00%)~301,148k301,162kp=0.109 n=6
Parse Time2.18s (± 1.25%)2.17s (± 0.38%)~2.16s2.18sp=0.558 n=6
Bind Time1.11s (± 0.46%)1.11s (± 0.00%)~1.11s1.11sp=0.174 n=6
Check Time7.21s (± 0.38%)7.20s (± 0.43%)~7.17s7.25sp=0.807 n=6
Emit Time3.99s (± 0.27%)3.99s (± 0.56%)~3.97s4.02sp=0.622 n=6
Total Time14.48s (± 0.22%)14.48s (± 0.33%)~14.43s14.56sp=0.688 n=6
material-ui - node (v16.17.1, x64)
Memory used479,449k (± 0.00%)479,449k (± 0.00%)~479,436k479,458kp=0.936 n=6
Parse Time3.15s (± 0.20%)3.15s (± 0.26%)~3.15s3.17sp=0.599 n=6
Bind Time0.91s (± 0.00%)0.91s (± 0.45%)~0.91s0.92sp=0.405 n=6
Check Time17.76s (± 0.44%)17.82s (± 0.38%)~17.73s17.92sp=0.261 n=6
Emit Time0.00s (± 0.00%)0.00s (± 0.00%)~0.00s0.00sp=1.000 n=6
Total Time21.82s (± 0.37%)21.88s (± 0.33%)~21.78s21.99sp=0.297 n=6
xstate - node (v16.17.1, x64)
Memory used542,811k (± 0.01%)542,820k (± 0.02%)~542,768k542,980kp=0.936 n=6
Parse Time3.71s (± 0.20%)3.70s (± 0.32%)~3.68s3.71sp=0.150 n=6
Bind Time1.36s (± 3.67%)1.38s (± 4.67%)~1.34s1.47sp=0.340 n=6
Check Time3.29s (± 2.33%)3.26s (± 2.77%)~3.14s3.33sp=0.808 n=6
Emit Time0.08s (± 0.00%)0.08s (± 0.00%)~0.08s0.08sp=1.000 n=6
Total Time8.44s (± 0.43%)8.42s (± 0.47%)~8.37s8.46sp=0.630 n=6
System info unknown
Hosts
  • node (v16.17.1, x64)
Scenarios
  • Angular - node (v16.17.1, x64)
  • Compiler-Unions - node (v16.17.1, x64)
  • Monaco - node (v16.17.1, x64)
  • TFS - node (v16.17.1, x64)
  • material-ui - node (v16.17.1, x64)
  • xstate - node (v16.17.1, x64)
BenchmarkNameIterations
Currentpr6
Baselinebaseline6

tsserver

Comparison Report - baseline..pr
MetricbaselineprDeltaBestWorstp-value
Compiler-UnionsTSServer - node (v16.17.1, x64)
Req 1 - updateOpen2,494ms (± 0.13%)2,492ms (± 0.13%)~2,486ms2,496msp=0.256 n=6
Req 2 - geterr5,931ms (± 0.17%)5,949ms (± 0.36%)~5,916ms5,971msp=0.128 n=6
Req 3 - references343ms (± 0.44%)342ms (± 0.24%)~341ms343msp=1.000 n=6
Req 4 - navto278ms (± 0.30%)277ms (± 0.27%)~276ms278msp=0.652 n=6
Req 5 - completionInfo count1,356 (± 0.00%)1,356 (± 0.00%)~1,3561,356p=1.000 n=6
Req 5 - completionInfo87ms (± 7.34%)88ms (± 8.70%)~76ms94msp=0.933 n=6
CompilerTSServer - node (v16.17.1, x64)
Req 1 - updateOpen2,616ms (± 0.41%)2,631ms (± 0.77%)~2,609ms2,662msp=0.128 n=6
Req 2 - geterr4,758ms (± 0.26%)4,771ms (± 0.18%)~4,760ms4,785msp=0.066 n=6
Req 3 - references350ms (± 0.12%)352ms (± 0.60%)+2ms (+ 0.52%)350ms356msp=0.025 n=6
Req 4 - navto270ms (± 0.20%)269ms (± 0.49%)~267ms271msp=0.663 n=6
Req 5 - completionInfo count1,518 (± 0.00%)1,518 (± 0.00%)~1,5181,518p=1.000 n=6
Req 5 - completionInfo79ms (± 0.80%)78ms (± 3.39%)~73ms80msp=0.787 n=6
xstateTSServer - node (v16.17.1, x64)
Req 1 - updateOpen2,718ms (± 0.23%)2,721ms (± 0.24%)~2,712ms2,731msp=0.810 n=6
Req 2 - geterr1,950ms (± 2.28%)1,956ms (± 1.50%)~1,898ms1,977msp=0.936 n=6
Req 3 - references133ms (± 6.77%)137ms (± 2.67%)~134ms141msp=0.459 n=6
Req 4 - navto352ms (± 0.61%)353ms (± 0.70%)~350ms357msp=0.514 n=6
Req 5 - completionInfo count2,071 (± 0.00%)2,071 (± 0.00%)~2,0712,071p=1.000 n=6
Req 5 - completionInfo316ms (± 1.67%)320ms (± 2.13%)~313ms327msp=0.332 n=6
System info unknown
Hosts
  • node (v16.17.1, x64)
Scenarios
  • CompilerTSServer - node (v16.17.1, x64)
  • Compiler-UnionsTSServer - node (v16.17.1, x64)
  • xstateTSServer - node (v16.17.1, x64)
BenchmarkNameIterations
Currentpr6
Baselinebaseline6

Startup

Comparison Report - baseline..pr
MetricbaselineprDeltaBestWorstp-value
tsc-startup - node (v16.17.1, x64)
Execution time155.57ms (± 0.15%)155.52ms (± 0.16%)-0.06ms (- 0.04%)154.51ms160.33msp=0.002 n=600
tsserver-startup - node (v16.17.1, x64)
Execution time230.35ms (± 0.14%)230.97ms (± 0.14%)+0.62ms (+ 0.27%)229.48ms238.50msp=0.000 n=600
tsserverlibrary-startup - node (v16.17.1, x64)
Execution time235.06ms (± 0.13%)235.89ms (± 0.17%)+0.83ms (+ 0.35%)234.42ms245.58msp=0.000 n=600
typescript-startup - node (v16.17.1, x64)
Execution time235.56ms (± 0.13%)235.59ms (± 0.14%)~234.28ms241.84msp=0.405 n=600
System info unknown
Hosts
  • node (v16.17.1, x64)
Scenarios
  • tsc-startup - node (v16.17.1, x64)
  • tsserver-startup - node (v16.17.1, x64)
  • tsserverlibrary-startup - node (v16.17.1, x64)
  • typescript-startup - node (v16.17.1, x64)
BenchmarkNameIterations
Currentpr6
Baselinebaseline6

Developer Information:

Download Benchmarks

@typescript-bot

Copy link
Copy Markdown
Contributor

Gabriela Araujo Britto (@gabritto) Here are the results of running the top-repos suite comparing main and refs/pull/55371/merge:

Everything looks good!

@gabritto

Copy link
Copy Markdown
Member

TypeScript Bot (@typescript-bot) pack this

@typescript-bot

TypeScript Bot (typescript-bot) commented Aug 24, 2023

Copy link
Copy Markdown
Contributor

Heya Gabriela Araujo Britto (@gabritto), I've started to run the tarball bundle task on this PR at d6fe15f. You can monitor the build here.

@typescript-bot

TypeScript Bot (typescript-bot) commented Aug 24, 2023

Copy link
Copy Markdown
Contributor

Hey Gabriela Araujo Britto (@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/156933/artifacts?artifactName=tgz&fileId=C27438AFFBBAA937BCA8EEFDEC3D1E6531B7CF21245096FDB6B1615E6DFB372202&fileName=/typescript-5.3.0-insiders.20230824.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.3.0-pr-55371-11".;

Comment threadsrc/compiler/checker.ts
@typescript-bot

Copy link
Copy Markdown
Contributor

Hey Gabriela Araujo Britto (@gabritto), the results of running the DT tests are ready.
Everything looks the same!
You can check the log here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

While this might be a true observation - ${T} is identical to T when T is only string-like - this isn't how we should implement it, imo. Rather than messing with type relations, this should be true on construction, eg, inside getTemplateLiteralType we should check for and produce this simplification, just so the simplifiable type identity never even exists inside the checker. A "late" simplification like this we should generally only do if it's too costly/circularity inducing to check upfront, but I don't think that'll be the case here (and, broadly speaking, could be done in getSimplifiedType rather than as a new relationship rule).

As an aside that won't really matter once that's done, since I do think we can do that, there's also an inference issue here, which is probably the better, broader fix for the original problem (which can probably be rewritten to have non-string constraints). When we see ${T} and infer to ${U}, the texts all match - ideally I'd think we want to infer T to U as a better match, no template wrapper required.

@Andarist
Mateusz Burzyński (Andarist)force-pushed the fix/template-literal-type-with-no-texts-relations branch from a3d3a15 to aac8961CompareJanuary 25, 2024 07:30
@AndaristMateusz Burzyński (Andarist) changed the title Improved relationship checking for template literal types with a single placeholder and no extra textsReduce template literal types with a single placeholder and no extra textsJan 25, 2024
@typescript-bot

TypeScript Bot (typescript-bot) commented Jan 25, 2024

Copy link
Copy Markdown
Contributor

Heya Gabriela Araujo Britto (@gabritto), I've started to run the regular perf test suite on this PR at aac8961. You can monitor the build here.

Update: The results are in!

@typescript-bot

TypeScript Bot (typescript-bot) commented Jan 25, 2024

Copy link
Copy Markdown
Contributor

Heya Gabriela Araujo Britto (@gabritto), I've started to run the diff-based user code test suite on this PR at aac8961. You can monitor the build here.

Update: The results are in!

@typescript-bot

TypeScript Bot (typescript-bot) commented Jan 25, 2024

Copy link
Copy Markdown
Contributor

Heya Gabriela Araujo Britto (@gabritto), I've started to run the parallelized Definitely Typed test suite on this PR at aac8961. You can monitor the build here.

Update: The results are in!

@typescript-bot

TypeScript Bot (typescript-bot) commented Jan 25, 2024

Copy link
Copy Markdown
Contributor

Heya Gabriela Araujo Britto (@gabritto), I've started to run the tarball bundle task on this PR at aac8961. You can monitor the build here.

@typescript-bot

TypeScript Bot (typescript-bot) commented Jan 25, 2024

Copy link
Copy Markdown
Contributor

Heya Gabriela Araujo Britto (@gabritto), I've started to run the diff-based top-repos suite on this PR at aac8961. You can monitor the build here.

Update: The results are in!

@typescript-bot

TypeScript Bot (typescript-bot) commented Jan 25, 2024

Copy link
Copy Markdown
Contributor

Hey Gabriela Araujo Britto (@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/159654/artifacts?artifactName=tgz&fileId=8DF46471F7BB7E8F18C2416BA60BE57230B718D774C6492BF8000692BB07304302&fileName=/typescript-5.4.0-insiders.20240125.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-55371-20".;

texts.length === 2 && texts[0] === "" && texts[1] === ""
// literals (including string enums) are stringified below
&& !(types[0].flags & TypeFlags.Literal)
// infer T extends StringLike can't be unwrapped eagerly

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do you have an example of when this matters? I.e. an example of why we shouldn't unwrapp infer T?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

it's mainly because of how string enums might be "stringified" by template literal types

constenumStringLiteralEnum{Zero="0",True="true",False="false",Undefined="undefined",Null="null"}typeTStringLiteralEnum0="0"extends `${infer TextendsStringLiteralEnum}` ? T : never;// ^? type TStringLiteralEnum0 = StringLiteralEnum.ZerotypeTStringLiteralEnum0Unwrapped="0"extends infer TextendsStringLiteralEnum ? T : never;// ^? type TStringLiteralEnum0Unwrapped = never

@typescript-bot

Copy link
Copy Markdown
Contributor

Gabriela Araujo Britto (@gabritto) Here are the results of running the user test suite comparing main and refs/pull/55371/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

@gabritto

Gabriela Araujo Britto (gabritto) commented Jan 25, 2024

Copy link
Copy Markdown
Member

Mateusz Burzyński (@Andarist) do you intend to fix the inference problem as well? (see #56659 (comment)).
Also, I'm wondering if inference is the only place where we construct types like ${T} where T is stringlike... If it is, fixing inference would mean this PR is not needed, but otherwise this PR is still needed.

@typescript-bot

Copy link
Copy Markdown
Contributor

Gabriela Araujo Britto (@gabritto)
The results of the perf run you requested are in!

Here they are:

tsc

Comparison Report - baseline..pr
MetricbaselineprDeltaBestWorstp-value
Angular - node (v18.15.0, x64)
Memory used295,649k (± 0.01%)295,641k (± 0.01%)~295,608k295,680kp=0.936 n=6
Parse Time2.66s (± 0.37%)2.66s (± 0.28%)~2.65s2.67sp=0.858 n=6
Bind Time0.83s (± 0.90%)0.83s (± 1.24%)~0.82s0.85sp=0.931 n=6
Check Time8.20s (± 0.46%)8.19s (± 0.46%)~8.12s8.21sp=0.625 n=6
Emit Time7.09s (± 0.28%)7.10s (± 0.29%)~7.08s7.12sp=0.142 n=6
Total Time18.78s (± 0.08%)18.78s (± 0.12%)~18.74s18.81sp=0.868 n=6
Compiler-Unions - node (v18.15.0, x64)
Memory used194,430k (± 1.65%)191,514k (± 0.02%)~191,487k191,584kp=0.261 n=6
Parse Time1.36s (± 1.20%)1.36s (± 1.43%)~1.33s1.38sp=0.788 n=6
Bind Time0.72s (± 0.57%)0.72s (± 0.00%)~0.72s0.72sp=0.405 n=6
Check Time9.35s (± 0.45%)9.34s (± 0.47%)~9.30s9.41sp=0.871 n=6
Emit Time2.62s (± 0.66%)2.63s (± 0.57%)~2.61s2.65sp=0.465 n=6
Total Time14.05s (± 0.22%)14.05s (± 0.23%)~14.00s14.09sp=1.000 n=6
Monaco - node (v18.15.0, x64)
Memory used347,449k (± 0.00%)347,456k (± 0.01%)~347,428k347,482kp=0.575 n=6
Parse Time2.48s (± 0.47%)2.48s (± 0.40%)~2.46s2.49sp=1.000 n=6
Bind Time0.93s (± 0.56%)0.92s (± 0.59%)~0.92s0.93sp=0.640 n=6
Check Time6.92s (± 0.21%)6.92s (± 0.44%)~6.88s6.96sp=0.870 n=6
Emit Time4.05s (± 0.34%)4.06s (± 0.51%)~4.03s4.09sp=1.000 n=6
Total Time14.38s (± 0.10%)14.38s (± 0.21%)~14.34s14.43sp=0.871 n=6
TFS - node (v18.15.0, x64)
Memory used302,830k (± 0.01%)302,841k (± 0.00%)~302,831k302,861kp=0.375 n=6
Parse Time2.00s (± 0.75%)2.03s (± 0.40%)+0.02s (+ 1.16%)2.02s2.04sp=0.015 n=6
Bind Time1.01s (± 1.49%)1.00s (± 0.81%)~1.00s1.02sp=0.924 n=6
Check Time6.33s (± 0.40%)6.32s (± 0.33%)~6.30s6.36sp=0.935 n=6
Emit Time3.59s (± 0.14%)3.59s (± 0.48%)~3.57s3.62sp=0.667 n=6
Total Time12.93s (± 0.09%)12.94s (± 0.20%)~12.92s12.98sp=0.622 n=6
material-ui - node (v18.15.0, x64)
Memory used511,297k (± 0.01%)511,289k (± 0.00%)~511,267k511,323kp=1.000 n=6
Parse Time2.64s (± 0.81%)2.65s (± 0.66%)~2.63s2.68sp=0.288 n=6
Bind Time0.99s (± 1.04%)0.99s (± 0.82%)~0.98s1.00sp=0.928 n=6
Check Time17.18s (± 0.24%)17.21s (± 0.26%)~17.14s17.27sp=0.199 n=6
Emit Time0.00s (± 0.00%)0.00s (± 0.00%)~0.00s0.00sp=1.000 n=6
Total Time20.81s (± 0.22%)20.86s (± 0.28%)~20.77s20.95sp=0.226 n=6
mui-docs - node (v18.15.0, x64)
Memory used1,694,500k (± 0.00%)1,694,518k (± 0.00%)~1,694,457k1,694,560kp=0.378 n=6
Parse Time6.52s (± 0.51%)6.54s (± 0.54%)~6.52s6.61sp=0.466 n=6
Bind Time2.36s (± 0.35%)2.36s (± 0.62%)~2.34s2.38sp=1.000 n=6
Check Time55.19s (± 0.43%)55.18s (± 0.33%)~55.02s55.51sp=0.873 n=6
Emit Time0.16s (± 0.00%)0.16s (± 2.52%)~0.16s0.17sp=0.405 n=6
Total Time64.23s (± 0.40%)64.24s (± 0.28%)~64.07s64.54sp=0.810 n=6
self-build-src - node (v18.15.0, x64)
Memory used2,412,956k (± 0.01%)2,413,189k (± 0.02%)~2,412,611k2,413,900kp=0.378 n=6
Parse Time4.94s (± 0.90%)4.93s (± 0.41%)~4.90s4.95sp=0.630 n=6
Bind Time1.88s (± 0.40%)1.88s (± 0.55%)~1.87s1.90sp=0.931 n=6
Check Time33.48s (± 0.51%)33.43s (± 0.29%)~33.26s33.51sp=1.000 n=6
Emit Time2.71s (± 1.23%)2.70s (± 1.07%)~2.66s2.73sp=0.521 n=6
Total Time43.03s (± 0.54%)42.95s (± 0.28%)~42.72s43.08sp=0.873 n=6
self-compiler - node (v18.15.0, x64)
Memory used419,720k (± 0.01%)419,751k (± 0.00%)+31k (+ 0.01%)419,732k419,773kp=0.045 n=6
Parse Time2.75s (± 3.34%)2.72s (± 3.02%)~2.65s2.84sp=0.573 n=6
Bind Time1.15s (± 6.86%)1.17s (± 6.64%)~1.07s1.23sp=0.935 n=6
Check Time15.10s (± 0.19%)15.05s (± 0.20%)-0.05s (- 0.33%)15.00s15.08sp=0.030 n=6
Emit Time1.15s (± 1.16%)1.15s (± 1.02%)~1.13s1.16sp=1.000 n=6
Total Time20.14s (± 0.17%)20.08s (± 0.24%)-0.06s (- 0.31%)20.02s20.16sp=0.037 n=6
vscode - node (v18.15.0, x64)
Memory used2,808,558k (± 0.00%)2,808,536k (± 0.00%)~2,808,504k2,808,562kp=0.109 n=6
Parse Time10.61s (± 0.30%)10.62s (± 0.42%)~10.56s10.69sp=1.000 n=6
Bind Time3.39s (± 0.44%)3.39s (± 0.40%)~3.37s3.41sp=0.933 n=6
Check Time59.78s (± 0.77%)59.59s (± 0.47%)~59.19s59.96sp=0.689 n=6
Emit Time16.12s (± 0.33%)16.13s (± 0.48%)~16.03s16.23sp=1.000 n=6
Total Time89.91s (± 0.48%)89.73s (± 0.30%)~89.39s90.18sp=0.521 n=6
webpack - node (v18.15.0, x64)
Memory used392,571k (± 0.01%)392,551k (± 0.01%)~392,458k392,599kp=0.810 n=6
Parse Time3.07s (± 0.89%)3.04s (± 0.83%)~3.02s3.08sp=0.087 n=6
Bind Time1.39s (± 0.64%)1.40s (± 0.64%)~1.39s1.41sp=0.113 n=6
Check Time13.94s (± 0.36%)13.94s (± 0.43%)~13.88s14.02sp=0.688 n=6
Emit Time0.00s (± 0.00%)0.00s (± 0.00%)~0.00s0.00sp=1.000 n=6
Total Time18.40s (± 0.36%)18.38s (± 0.41%)~18.30s18.47sp=0.467 n=6
xstate - node (v18.15.0, x64)
Memory used513,380k (± 0.02%)513,382k (± 0.01%)~513,285k513,463kp=0.936 n=6
Parse Time3.26s (± 0.13%)3.28s (± 0.33%)+0.02s (+ 0.56%)3.26s3.29sp=0.016 n=6
Bind Time1.55s (± 0.35%)1.54s (± 0.00%)~1.54s1.54sp=0.071 n=6
Check Time2.84s (± 0.65%)2.85s (± 0.36%)~2.83s2.86sp=0.808 n=6
Emit Time0.08s (± 4.99%)0.08s (± 0.00%)~0.08s0.08sp=0.405 n=6
Total Time7.74s (± 0.22%)7.75s (± 0.27%)~7.71s7.77sp=0.329 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)
BenchmarkNameIterations
Currentpr6
Baselinebaseline6

tsserver

Comparison Report - baseline..pr
MetricbaselineprDeltaBestWorstp-value
Compiler-UnionsTSServer - node (v18.15.0, x64)
Req 1 - updateOpen2,337ms (± 0.49%)2,345ms (± 0.53%)~2,328ms2,365msp=0.378 n=6
Req 2 - geterr5,501ms (± 1.35%)5,489ms (± 1.27%)~5,436ms5,628msp=0.575 n=6
Req 3 - references326ms (± 1.19%)325ms (± 1.26%)~320ms332msp=0.682 n=6
Req 4 - navto276ms (± 1.00%)278ms (± 0.63%)~275ms279msp=0.357 n=6
Req 5 - completionInfo count1,356 (± 0.00%)1,356 (± 0.00%)~1,3561,356p=1.000 n=6
Req 5 - completionInfo85ms (± 9.22%)86ms (± 8.50%)~79ms95msp=0.798 n=6
CompilerTSServer - node (v18.15.0, x64)
Req 1 - updateOpen2,476ms (± 0.68%)2,489ms (± 0.59%)~2,475ms2,513msp=0.169 n=6
Req 2 - geterr4,225ms (± 1.87%)4,158ms (± 1.66%)~4,109ms4,295msp=0.378 n=6
Req 3 - references336ms (± 1.50%)340ms (± 1.16%)~332ms342msp=0.310 n=6
Req 4 - navto284ms (± 0.49%)285ms (± 0.44%)~283ms286msp=0.099 n=6
Req 5 - completionInfo count1,518 (± 0.00%)1,518 (± 0.00%)~1,5181,518p=1.000 n=6
Req 5 - completionInfo80ms (± 7.02%)86ms (± 5.31%)~78ms90msp=0.062 n=6
xstateTSServer - node (v18.15.0, x64)
Req 1 - updateOpen2,608ms (± 0.72%)2,609ms (± 0.56%)~2,585ms2,627msp=0.810 n=6
Req 2 - geterr1,711ms (± 1.96%)1,706ms (± 3.07%)~1,652ms1,769msp=0.810 n=6
Req 3 - references113ms (± 8.49%)120ms (± 8.61%)~107ms128msp=0.220 n=6
Req 4 - navto370ms (± 0.33%)367ms (± 0.95%)~362ms371msp=0.079 n=6
Req 5 - completionInfo count2,078 (± 0.00%)2,078 (± 0.00%)~2,0782,078p=1.000 n=6
Req 5 - completionInfo308ms (± 2.24%)307ms (± 2.28%)~300ms316msp=1.000 n=6
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • CompilerTSServer - node (v18.15.0, x64)
  • Compiler-UnionsTSServer - node (v18.15.0, x64)
  • xstateTSServer - node (v18.15.0, x64)
BenchmarkNameIterations
Currentpr6
Baselinebaseline6

startup

Comparison Report - baseline..pr
MetricbaselineprDeltaBestWorstp-value
tsc-startup - node (v18.15.0, x64)
Execution time152.75ms (± 0.21%)152.62ms (± 0.18%)-0.13ms (- 0.08%)151.53ms156.50msp=0.001 n=600
tsserver-startup - node (v18.15.0, x64)
Execution time228.93ms (± 0.14%)228.80ms (± 0.15%)-0.13ms (- 0.06%)227.45ms231.81msp=0.000 n=600
tsserverlibrary-startup - node (v18.15.0, x64)
Execution time230.77ms (± 0.19%)230.74ms (± 0.18%)~228.90ms236.41msp=0.409 n=600
typescript-startup - node (v18.15.0, x64)
Execution time230.47ms (± 0.18%)230.39ms (± 0.17%)-0.08ms (- 0.04%)228.84ms233.80msp=0.023 n=600
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • tsc-startup - node (v18.15.0, x64)
  • tsserver-startup - node (v18.15.0, x64)
  • tsserverlibrary-startup - node (v18.15.0, x64)
  • typescript-startup - node (v18.15.0, x64)
BenchmarkNameIterations
Currentpr6
Baselinebaseline6

Developer Information:

Download Benchmarks

@typescript-bot

Copy link
Copy Markdown
Contributor

Hey Gabriela Araujo Britto (@gabritto), 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

Gabriela Araujo Britto (@gabritto) Here are the results of running the top-repos suite comparing main and refs/pull/55371/merge:

Everything looks good!

@Andarist

Copy link
Copy Markdown
ContributorAuthor

Mateusz Burzyński (@Andarist) do you intend to fix the inference problem as well? (see #56659 (comment)).

I can investigate this

Also, I'm wondering if inference is the only place where we construct types like ${T} where T is stringlike... If it is, fixing inference would mean this PR is not needed, but otherwise this PR is still needed.

Users might also construct such types and it makes sense to allow those:

functionf3<T3extends"a"|"b">(x: T3){consttest1: `${T3}` =xconsttest2: T3=""as `${T3}`;}

To allow this we need to either do this simplification or mess with the relationship checking (what I had here before).

@gabritto

Copy link
Copy Markdown
Member

Mateusz Burzyński (@Andarist) do you intend to fix the inference problem as well? (see #56659 (comment)).

I can investigate this

Also, I'm wondering if inference is the only place where we construct types like ${T} where T is stringlike... If it is, fixing inference would mean this PR is not needed, but otherwise this PR is still needed.

Users might also construct such types and it makes sense to allow those:

functionf3<T3extends"a"|"b">(x: T3){consttest1: `${T3}` =xconsttest2: T3=""as `${T3}`;}

To allow this we need to either do this simplification or mess with the relationship checking (what I had here before).

Right, I remember now. I think you mentioned that before but I had forgotten, sorry.

@gabritto

Copy link
Copy Markdown
Member

Mateusz Burzyński (@Andarist) can you update this with latest main so I can merge?

@Andarist

Copy link
Copy Markdown
ContributorAuthor

Gabriela Araujo Britto (@gabritto) with pleasure! done :)

@ahejlsberg

Copy link
Copy Markdown
Member

This PR is effectively a breaking change as demonstrated in #58687. I'm not sure I like it.

@Andarist

Mateusz Burzyński (Andarist) commented May 29, 2024

Copy link
Copy Markdown
ContributorAuthor

Note that this PR started as a rule in type relationships (but perhaps it wasnt working for some enum-related cases correctly either), it was requested to make it unwrap those eagerly instead

@ahejlsberg

Anders Hejlsberg (ahejlsberg) commented May 29, 2024

Copy link
Copy Markdown
Member

First off, the real fix for #56659 appears to be #57808 which was merged a few days after this PR. When I back out this PR, the repro in #56659 still checks with no errors.

That leaves #55364, which with this PR backed out exhibits the following behavior:

interfaceTypeMap{a: 'A'b: 'B'}declareconstf: <Textends'a'|'b'>(x: `${T}`)=>TypeMap[T];typeF1=<Textends'a'|'b'>(x: `${T}`)=>TypeMap[T];constf1: F1=f;// OktypeF2=<Textends'a'|'b'>(x: `${T}`)=>TypeMap[`${T}`];constf2: F2=f;// Error, T is not assignable to `${T}`

In my opinion that's working as intended. It is true that for a subset of types T, instantiations of T will be assignable to instantiations of `${T}`, but I don't think it is super important to special case that. In any case, if we decide to support it, it would have to be something we do in type relations.

All up, my recommendation is that we revert this PR.

@gabritto

Copy link
Copy Markdown
Member

I'll revert this.

@Andarist

Copy link
Copy Markdown
ContributorAuthor

Gabriela Araujo Britto (@gabritto) i have proposed fix in the works, i should be able to post it soon

Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

For Backlog BugPRs that fix a backlog bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Template literal value not assignable to template literal type Template literal type resolution

6 participants

@Andarist@gabritto@typescript-bot@ahejlsberg@weswigham@sandersn