Skip to content

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

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

Conversation

Andarist
Copy link
Contributor

@Andarist Andarist commented Aug 14, 2023

fixes #55364
fixes #56659

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Aug 14, 2023
@Andarist Andarist force-pushed the fix/template-literal-type-with-no-texts-relations branch from b6b579b to 12dbb98 Compare August 14, 2023 17:34
@typescript-bot typescript-bot added For Backlog Bug PRs that fix a backlog bug and removed For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Aug 16, 2023
@sandersn sandersn requested review from weswigham and gabritto August 23, 2023 23:17
@gabritto

This comment was marked as duplicate.

@gabritto
Copy link
Member

@typescript-bot run DT
@typescript-bot user test this
@typescript-bot test top100
@typescript-bot perf test this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Aug 24, 2023

Heya @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
Copy link
Collaborator

typescript-bot commented Aug 24, 2023

Heya @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
Copy link
Collaborator

typescript-bot commented Aug 24, 2023

Heya @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
Copy link
Collaborator

typescript-bot commented Aug 24, 2023

Heya @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
Collaborator

@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)

@typescript-bot
Copy link
Collaborator

@gabritto
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 (v16.17.1, x64)
Memory used 300,248k (± 0.01%) 300,249k (± 0.01%) ~ 300,219k 300,269k p=0.936 n=6
Parse Time 3.02s (± 0.18%) 3.02s (± 0.00%) ~ 3.02s 3.02s p=0.071 n=6
Bind Time 0.93s (± 0.00%) 0.93s (± 0.00%) ~ 0.93s 0.93s p=1.000 n=6
Check Time 9.28s (± 0.39%) 9.30s (± 0.34%) ~ 9.26s 9.35s p=0.418 n=6
Emit Time 7.63s (± 0.34%) 7.64s (± 0.43%) ~ 7.59s 7.69s p=0.685 n=6
Total Time 20.87s (± 0.25%) 20.89s (± 0.20%) ~ 20.84s 20.94s p=0.421 n=6
Compiler-Unions - node (v16.17.1, x64)
Memory used 194,483k (± 0.66%) 193,976k (± 0.00%) ~ 193,965k 193,982k p=0.872 n=6
Parse Time 1.58s (± 0.26%) 1.58s (± 0.00%) ~ 1.58s 1.58s p=0.405 n=6
Bind Time 0.80s (± 0.51%) 0.80s (± 0.51%) ~ 0.79s 0.80s p=1.000 n=6
Check Time 9.90s (± 0.42%) 9.90s (± 0.14%) ~ 9.88s 9.92s p=0.628 n=6
Emit Time 2.73s (± 0.20%) 2.74s (± 0.31%) ~ 2.72s 2.74s p=0.855 n=6
Total Time 15.02s (± 0.29%) 15.01s (± 0.10%) ~ 14.99s 15.03s p=1.000 n=6
Monaco - node (v16.17.1, x64)
Memory used 347,146k (± 0.00%) 347,131k (± 0.01%) ~ 347,091k 347,169k p=0.936 n=6
Parse Time 2.69s (± 0.31%) 2.69s (± 0.15%) ~ 2.69s 2.70s p=0.097 n=6
Bind Time 0.99s (± 0.00%) 0.99s (± 0.52%) ~ 0.99s 1.00s p=0.174 n=6
Check Time 7.91s (± 0.30%) 7.91s (± 0.18%) ~ 7.89s 7.93s p=0.511 n=6
Emit Time 4.27s (± 0.34%) 4.26s (± 0.39%) ~ 4.23s 4.27s p=0.617 n=6
Total Time 15.85s (± 0.11%) 15.85s (± 0.15%) ~ 15.82s 15.88s p=0.570 n=6
TFS - node (v16.17.1, x64)
Memory used 301,146k (± 0.00%) 301,157k (± 0.00%) ~ 301,148k 301,162k p=0.109 n=6
Parse Time 2.18s (± 1.25%) 2.17s (± 0.38%) ~ 2.16s 2.18s p=0.558 n=6
Bind Time 1.11s (± 0.46%) 1.11s (± 0.00%) ~ 1.11s 1.11s p=0.174 n=6
Check Time 7.21s (± 0.38%) 7.20s (± 0.43%) ~ 7.17s 7.25s p=0.807 n=6
Emit Time 3.99s (± 0.27%) 3.99s (± 0.56%) ~ 3.97s 4.02s p=0.622 n=6
Total Time 14.48s (± 0.22%) 14.48s (± 0.33%) ~ 14.43s 14.56s p=0.688 n=6
material-ui - node (v16.17.1, x64)
Memory used 479,449k (± 0.00%) 479,449k (± 0.00%) ~ 479,436k 479,458k p=0.936 n=6
Parse Time 3.15s (± 0.20%) 3.15s (± 0.26%) ~ 3.15s 3.17s p=0.599 n=6
Bind Time 0.91s (± 0.00%) 0.91s (± 0.45%) ~ 0.91s 0.92s p=0.405 n=6
Check Time 17.76s (± 0.44%) 17.82s (± 0.38%) ~ 17.73s 17.92s p=0.261 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 21.82s (± 0.37%) 21.88s (± 0.33%) ~ 21.78s 21.99s p=0.297 n=6
xstate - node (v16.17.1, x64)
Memory used 542,811k (± 0.01%) 542,820k (± 0.02%) ~ 542,768k 542,980k p=0.936 n=6
Parse Time 3.71s (± 0.20%) 3.70s (± 0.32%) ~ 3.68s 3.71s p=0.150 n=6
Bind Time 1.36s (± 3.67%) 1.38s (± 4.67%) ~ 1.34s 1.47s p=0.340 n=6
Check Time 3.29s (± 2.33%) 3.26s (± 2.77%) ~ 3.14s 3.33s p=0.808 n=6
Emit Time 0.08s (± 0.00%) 0.08s (± 0.00%) ~ 0.08s 0.08s p=1.000 n=6
Total Time 8.44s (± 0.43%) 8.42s (± 0.47%) ~ 8.37s 8.46s p=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)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

tsserver

Comparison Report - baseline..pr
Metric baseline pr Delta Best Worst p-value
Compiler-UnionsTSServer - node (v16.17.1, x64)
Req 1 - updateOpen 2,494ms (± 0.13%) 2,492ms (± 0.13%) ~ 2,486ms 2,496ms p=0.256 n=6
Req 2 - geterr 5,931ms (± 0.17%) 5,949ms (± 0.36%) ~ 5,916ms 5,971ms p=0.128 n=6
Req 3 - references 343ms (± 0.44%) 342ms (± 0.24%) ~ 341ms 343ms p=1.000 n=6
Req 4 - navto 278ms (± 0.30%) 277ms (± 0.27%) ~ 276ms 278ms p=0.652 n=6
Req 5 - completionInfo count 1,356 (± 0.00%) 1,356 (± 0.00%) ~ 1,356 1,356 p=1.000 n=6
Req 5 - completionInfo 87ms (± 7.34%) 88ms (± 8.70%) ~ 76ms 94ms p=0.933 n=6
CompilerTSServer - node (v16.17.1, x64)
Req 1 - updateOpen 2,616ms (± 0.41%) 2,631ms (± 0.77%) ~ 2,609ms 2,662ms p=0.128 n=6
Req 2 - geterr 4,758ms (± 0.26%) 4,771ms (± 0.18%) ~ 4,760ms 4,785ms p=0.066 n=6
Req 3 - references 350ms (± 0.12%) 352ms (± 0.60%) +2ms (+ 0.52%) 350ms 356ms p=0.025 n=6
Req 4 - navto 270ms (± 0.20%) 269ms (± 0.49%) ~ 267ms 271ms p=0.663 n=6
Req 5 - completionInfo count 1,518 (± 0.00%) 1,518 (± 0.00%) ~ 1,518 1,518 p=1.000 n=6
Req 5 - completionInfo 79ms (± 0.80%) 78ms (± 3.39%) ~ 73ms 80ms p=0.787 n=6
xstateTSServer - node (v16.17.1, x64)
Req 1 - updateOpen 2,718ms (± 0.23%) 2,721ms (± 0.24%) ~ 2,712ms 2,731ms p=0.810 n=6
Req 2 - geterr 1,950ms (± 2.28%) 1,956ms (± 1.50%) ~ 1,898ms 1,977ms p=0.936 n=6
Req 3 - references 133ms (± 6.77%) 137ms (± 2.67%) ~ 134ms 141ms p=0.459 n=6
Req 4 - navto 352ms (± 0.61%) 353ms (± 0.70%) ~ 350ms 357ms p=0.514 n=6
Req 5 - completionInfo count 2,071 (± 0.00%) 2,071 (± 0.00%) ~ 2,071 2,071 p=1.000 n=6
Req 5 - completionInfo 316ms (± 1.67%) 320ms (± 2.13%) ~ 313ms 327ms p=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)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

Startup

Comparison Report - baseline..pr
Metric baseline pr Delta Best Worst p-value
tsc-startup - node (v16.17.1, x64)
Execution time 155.57ms (± 0.15%) 155.52ms (± 0.16%) -0.06ms (- 0.04%) 154.51ms 160.33ms p=0.002 n=600
tsserver-startup - node (v16.17.1, x64)
Execution time 230.35ms (± 0.14%) 230.97ms (± 0.14%) +0.62ms (+ 0.27%) 229.48ms 238.50ms p=0.000 n=600
tsserverlibrary-startup - node (v16.17.1, x64)
Execution time 235.06ms (± 0.13%) 235.89ms (± 0.17%) +0.83ms (+ 0.35%) 234.42ms 245.58ms p=0.000 n=600
typescript-startup - node (v16.17.1, x64)
Execution time 235.56ms (± 0.13%) 235.59ms (± 0.14%) ~ 234.28ms 241.84ms p=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)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

Developer Information:

Download Benchmarks

@typescript-bot
Copy link
Collaborator

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

Everything looks good!

@gabritto
Copy link
Member

@typescript-bot pack this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Aug 24, 2023

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Aug 24, 2023

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/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/[email protected]".;

@typescript-bot
Copy link
Collaborator

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

Copy link
Member

@weswigham weswigham left a comment

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 Andarist force-pushed the fix/template-literal-type-with-no-texts-relations branch from a3d3a15 to aac8961 Compare January 25, 2024 07:30
@Andarist Andarist changed the title Improved relationship checking for template literal types with a single placeholder and no extra texts Reduce template literal types with a single placeholder and no extra texts Jan 25, 2024
@gabritto
Copy link
Member

@typescript-bot run DT
@typescript-bot user test this
@typescript-bot test top200
@typescript-bot perf test this
@typescript-bot pack this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jan 25, 2024

Heya @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
Copy link
Collaborator

typescript-bot commented Jan 25, 2024

Heya @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
Copy link
Collaborator

typescript-bot commented Jan 25, 2024

Heya @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
Copy link
Collaborator

typescript-bot commented Jan 25, 2024

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jan 25, 2024

Heya @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
Copy link
Collaborator

typescript-bot commented Jan 25, 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/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/[email protected]".;

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
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
Contributor Author

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

const enum StringLiteralEnum { Zero = "0", True = "true", False = "false", Undefined = "undefined", Null = "null" }

type TStringLiteralEnum0 = "0" extends `${infer T extends StringLiteralEnum}` ? T : never;
//   ^? type TStringLiteralEnum0 = StringLiteralEnum.Zero
type TStringLiteralEnum0Unwrapped = "0" extends infer T extends StringLiteralEnum ? T : never;
//   ^? type TStringLiteralEnum0Unwrapped = never

@typescript-bot
Copy link
Collaborator

@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
Copy link
Member

gabritto commented Jan 25, 2024

@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
Collaborator

@gabritto
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,649k (± 0.01%) 295,641k (± 0.01%) ~ 295,608k 295,680k p=0.936 n=6
Parse Time 2.66s (± 0.37%) 2.66s (± 0.28%) ~ 2.65s 2.67s p=0.858 n=6
Bind Time 0.83s (± 0.90%) 0.83s (± 1.24%) ~ 0.82s 0.85s p=0.931 n=6
Check Time 8.20s (± 0.46%) 8.19s (± 0.46%) ~ 8.12s 8.21s p=0.625 n=6
Emit Time 7.09s (± 0.28%) 7.10s (± 0.29%) ~ 7.08s 7.12s p=0.142 n=6
Total Time 18.78s (± 0.08%) 18.78s (± 0.12%) ~ 18.74s 18.81s p=0.868 n=6
Compiler-Unions - node (v18.15.0, x64)
Memory used 194,430k (± 1.65%) 191,514k (± 0.02%) ~ 191,487k 191,584k p=0.261 n=6
Parse Time 1.36s (± 1.20%) 1.36s (± 1.43%) ~ 1.33s 1.38s p=0.788 n=6
Bind Time 0.72s (± 0.57%) 0.72s (± 0.00%) ~ 0.72s 0.72s p=0.405 n=6
Check Time 9.35s (± 0.45%) 9.34s (± 0.47%) ~ 9.30s 9.41s p=0.871 n=6
Emit Time 2.62s (± 0.66%) 2.63s (± 0.57%) ~ 2.61s 2.65s p=0.465 n=6
Total Time 14.05s (± 0.22%) 14.05s (± 0.23%) ~ 14.00s 14.09s p=1.000 n=6
Monaco - node (v18.15.0, x64)
Memory used 347,449k (± 0.00%) 347,456k (± 0.01%) ~ 347,428k 347,482k p=0.575 n=6
Parse Time 2.48s (± 0.47%) 2.48s (± 0.40%) ~ 2.46s 2.49s p=1.000 n=6
Bind Time 0.93s (± 0.56%) 0.92s (± 0.59%) ~ 0.92s 0.93s p=0.640 n=6
Check Time 6.92s (± 0.21%) 6.92s (± 0.44%) ~ 6.88s 6.96s p=0.870 n=6
Emit Time 4.05s (± 0.34%) 4.06s (± 0.51%) ~ 4.03s 4.09s p=1.000 n=6
Total Time 14.38s (± 0.10%) 14.38s (± 0.21%) ~ 14.34s 14.43s p=0.871 n=6
TFS - node (v18.15.0, x64)
Memory used 302,830k (± 0.01%) 302,841k (± 0.00%) ~ 302,831k 302,861k p=0.375 n=6
Parse Time 2.00s (± 0.75%) 2.03s (± 0.40%) +0.02s (+ 1.16%) 2.02s 2.04s p=0.015 n=6
Bind Time 1.01s (± 1.49%) 1.00s (± 0.81%) ~ 1.00s 1.02s p=0.924 n=6
Check Time 6.33s (± 0.40%) 6.32s (± 0.33%) ~ 6.30s 6.36s p=0.935 n=6
Emit Time 3.59s (± 0.14%) 3.59s (± 0.48%) ~ 3.57s 3.62s p=0.667 n=6
Total Time 12.93s (± 0.09%) 12.94s (± 0.20%) ~ 12.92s 12.98s p=0.622 n=6
material-ui - node (v18.15.0, x64)
Memory used 511,297k (± 0.01%) 511,289k (± 0.00%) ~ 511,267k 511,323k p=1.000 n=6
Parse Time 2.64s (± 0.81%) 2.65s (± 0.66%) ~ 2.63s 2.68s p=0.288 n=6
Bind Time 0.99s (± 1.04%) 0.99s (± 0.82%) ~ 0.98s 1.00s p=0.928 n=6
Check Time 17.18s (± 0.24%) 17.21s (± 0.26%) ~ 17.14s 17.27s p=0.199 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 20.81s (± 0.22%) 20.86s (± 0.28%) ~ 20.77s 20.95s p=0.226 n=6
mui-docs - node (v18.15.0, x64)
Memory used 1,694,500k (± 0.00%) 1,694,518k (± 0.00%) ~ 1,694,457k 1,694,560k p=0.378 n=6
Parse Time 6.52s (± 0.51%) 6.54s (± 0.54%) ~ 6.52s 6.61s p=0.466 n=6
Bind Time 2.36s (± 0.35%) 2.36s (± 0.62%) ~ 2.34s 2.38s p=1.000 n=6
Check Time 55.19s (± 0.43%) 55.18s (± 0.33%) ~ 55.02s 55.51s p=0.873 n=6
Emit Time 0.16s (± 0.00%) 0.16s (± 2.52%) ~ 0.16s 0.17s p=0.405 n=6
Total Time 64.23s (± 0.40%) 64.24s (± 0.28%) ~ 64.07s 64.54s p=0.810 n=6
self-build-src - node (v18.15.0, x64)
Memory used 2,412,956k (± 0.01%) 2,413,189k (± 0.02%) ~ 2,412,611k 2,413,900k p=0.378 n=6
Parse Time 4.94s (± 0.90%) 4.93s (± 0.41%) ~ 4.90s 4.95s p=0.630 n=6
Bind Time 1.88s (± 0.40%) 1.88s (± 0.55%) ~ 1.87s 1.90s p=0.931 n=6
Check Time 33.48s (± 0.51%) 33.43s (± 0.29%) ~ 33.26s 33.51s p=1.000 n=6
Emit Time 2.71s (± 1.23%) 2.70s (± 1.07%) ~ 2.66s 2.73s p=0.521 n=6
Total Time 43.03s (± 0.54%) 42.95s (± 0.28%) ~ 42.72s 43.08s p=0.873 n=6
self-compiler - node (v18.15.0, x64)
Memory used 419,720k (± 0.01%) 419,751k (± 0.00%) +31k (+ 0.01%) 419,732k 419,773k p=0.045 n=6
Parse Time 2.75s (± 3.34%) 2.72s (± 3.02%) ~ 2.65s 2.84s p=0.573 n=6
Bind Time 1.15s (± 6.86%) 1.17s (± 6.64%) ~ 1.07s 1.23s p=0.935 n=6
Check Time 15.10s (± 0.19%) 15.05s (± 0.20%) -0.05s (- 0.33%) 15.00s 15.08s p=0.030 n=6
Emit Time 1.15s (± 1.16%) 1.15s (± 1.02%) ~ 1.13s 1.16s p=1.000 n=6
Total Time 20.14s (± 0.17%) 20.08s (± 0.24%) -0.06s (- 0.31%) 20.02s 20.16s p=0.037 n=6
vscode - node (v18.15.0, x64)
Memory used 2,808,558k (± 0.00%) 2,808,536k (± 0.00%) ~ 2,808,504k 2,808,562k p=0.109 n=6
Parse Time 10.61s (± 0.30%) 10.62s (± 0.42%) ~ 10.56s 10.69s p=1.000 n=6
Bind Time 3.39s (± 0.44%) 3.39s (± 0.40%) ~ 3.37s 3.41s p=0.933 n=6
Check Time 59.78s (± 0.77%) 59.59s (± 0.47%) ~ 59.19s 59.96s p=0.689 n=6
Emit Time 16.12s (± 0.33%) 16.13s (± 0.48%) ~ 16.03s 16.23s p=1.000 n=6
Total Time 89.91s (± 0.48%) 89.73s (± 0.30%) ~ 89.39s 90.18s p=0.521 n=6
webpack - node (v18.15.0, x64)
Memory used 392,571k (± 0.01%) 392,551k (± 0.01%) ~ 392,458k 392,599k p=0.810 n=6
Parse Time 3.07s (± 0.89%) 3.04s (± 0.83%) ~ 3.02s 3.08s p=0.087 n=6
Bind Time 1.39s (± 0.64%) 1.40s (± 0.64%) ~ 1.39s 1.41s p=0.113 n=6
Check Time 13.94s (± 0.36%) 13.94s (± 0.43%) ~ 13.88s 14.02s p=0.688 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 18.40s (± 0.36%) 18.38s (± 0.41%) ~ 18.30s 18.47s p=0.467 n=6
xstate - node (v18.15.0, x64)
Memory used 513,380k (± 0.02%) 513,382k (± 0.01%) ~ 513,285k 513,463k p=0.936 n=6
Parse Time 3.26s (± 0.13%) 3.28s (± 0.33%) +0.02s (+ 0.56%) 3.26s 3.29s p=0.016 n=6
Bind Time 1.55s (± 0.35%) 1.54s (± 0.00%) ~ 1.54s 1.54s p=0.071 n=6
Check Time 2.84s (± 0.65%) 2.85s (± 0.36%) ~ 2.83s 2.86s p=0.808 n=6
Emit Time 0.08s (± 4.99%) 0.08s (± 0.00%) ~ 0.08s 0.08s p=0.405 n=6
Total Time 7.74s (± 0.22%) 7.75s (± 0.27%) ~ 7.71s 7.77s p=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)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

tsserver

Comparison Report - baseline..pr
Metric baseline pr Delta Best Worst p-value
Compiler-UnionsTSServer - node (v18.15.0, x64)
Req 1 - updateOpen 2,337ms (± 0.49%) 2,345ms (± 0.53%) ~ 2,328ms 2,365ms p=0.378 n=6
Req 2 - geterr 5,501ms (± 1.35%) 5,489ms (± 1.27%) ~ 5,436ms 5,628ms p=0.575 n=6
Req 3 - references 326ms (± 1.19%) 325ms (± 1.26%) ~ 320ms 332ms p=0.682 n=6
Req 4 - navto 276ms (± 1.00%) 278ms (± 0.63%) ~ 275ms 279ms p=0.357 n=6
Req 5 - completionInfo count 1,356 (± 0.00%) 1,356 (± 0.00%) ~ 1,356 1,356 p=1.000 n=6
Req 5 - completionInfo 85ms (± 9.22%) 86ms (± 8.50%) ~ 79ms 95ms p=0.798 n=6
CompilerTSServer - node (v18.15.0, x64)
Req 1 - updateOpen 2,476ms (± 0.68%) 2,489ms (± 0.59%) ~ 2,475ms 2,513ms p=0.169 n=6
Req 2 - geterr 4,225ms (± 1.87%) 4,158ms (± 1.66%) ~ 4,109ms 4,295ms p=0.378 n=6
Req 3 - references 336ms (± 1.50%) 340ms (± 1.16%) ~ 332ms 342ms p=0.310 n=6
Req 4 - navto 284ms (± 0.49%) 285ms (± 0.44%) ~ 283ms 286ms p=0.099 n=6
Req 5 - completionInfo count 1,518 (± 0.00%) 1,518 (± 0.00%) ~ 1,518 1,518 p=1.000 n=6
Req 5 - completionInfo 80ms (± 7.02%) 86ms (± 5.31%) ~ 78ms 90ms p=0.062 n=6
xstateTSServer - node (v18.15.0, x64)
Req 1 - updateOpen 2,608ms (± 0.72%) 2,609ms (± 0.56%) ~ 2,585ms 2,627ms p=0.810 n=6
Req 2 - geterr 1,711ms (± 1.96%) 1,706ms (± 3.07%) ~ 1,652ms 1,769ms p=0.810 n=6
Req 3 - references 113ms (± 8.49%) 120ms (± 8.61%) ~ 107ms 128ms p=0.220 n=6
Req 4 - navto 370ms (± 0.33%) 367ms (± 0.95%) ~ 362ms 371ms p=0.079 n=6
Req 5 - completionInfo count 2,078 (± 0.00%) 2,078 (± 0.00%) ~ 2,078 2,078 p=1.000 n=6
Req 5 - completionInfo 308ms (± 2.24%) 307ms (± 2.28%) ~ 300ms 316ms p=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)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

startup

Comparison Report - baseline..pr
Metric baseline pr Delta Best Worst p-value
tsc-startup - node (v18.15.0, x64)
Execution time 152.75ms (± 0.21%) 152.62ms (± 0.18%) -0.13ms (- 0.08%) 151.53ms 156.50ms p=0.001 n=600
tsserver-startup - node (v18.15.0, x64)
Execution time 228.93ms (± 0.14%) 228.80ms (± 0.15%) -0.13ms (- 0.06%) 227.45ms 231.81ms p=0.000 n=600
tsserverlibrary-startup - node (v18.15.0, x64)
Execution time 230.77ms (± 0.19%) 230.74ms (± 0.18%) ~ 228.90ms 236.41ms p=0.409 n=600
typescript-startup - node (v18.15.0, x64)
Execution time 230.47ms (± 0.18%) 230.39ms (± 0.17%) -0.08ms (- 0.04%) 228.84ms 233.80ms p=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)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

Developer Information:

Download Benchmarks

@typescript-bot
Copy link
Collaborator

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

@typescript-bot
Copy link
Collaborator

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

Everything looks good!

@Andarist
Copy link
Contributor Author

@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:

function f3<T3 extends "a" | "b">(x: T3) {
    const test1: `${T3}` = x    
    const test2: 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
Member

@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:

function f3<T3 extends "a" | "b">(x: T3) {
    const test1: `${T3}` = x    
    const test2: 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
Member

@Andarist can you update this with latest main so I can merge?

@Andarist
Copy link
Contributor Author

@gabritto with pleasure! done :)

@gabritto gabritto merged commit a64ea3a into microsoft:main Mar 14, 2024
@Andarist Andarist deleted the fix/template-literal-type-with-no-texts-relations branch March 14, 2024 20:48
@ahejlsberg
Copy link
Member

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

@Andarist
Copy link
Contributor Author

Andarist commented May 29, 2024

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
Copy link
Member

ahejlsberg commented May 29, 2024

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:

interface TypeMap {
    a: 'A'
    b: 'B'
}

declare const f: <T extends 'a' | 'b'>(x: `${T}`) => TypeMap[T];

type F1 = <T extends 'a' | 'b'>(x: `${T}`) => TypeMap[T];
const f1: F1 = f;  // Ok

type F2 = <T extends 'a' | 'b'>(x: `${T}`) => TypeMap[`${T}`];
const f2: 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
Member

I'll revert this.

@Andarist
Copy link
Contributor Author

@gabritto i have proposed fix in the works, i should be able to post it soon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Backlog Bug PRs 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
5 participants