Skip to content

Fixed an issue with string mappings over generic intersections not being deferred in conditional types - #55856

Merged
Nathan Shively-Sanders (sandersn) merged 5 commits into
microsoft:mainfrom
Andarist:fix/string-mapping-deferral
Oct 26, 2023
Merged

Fixed an issue with string mappings over generic intersections not being deferred in conditional types#55856
Nathan Shively-Sanders (sandersn) merged 5 commits into
microsoft:mainfrom
Andarist:fix/string-mapping-deferral

Conversation

@Andarist

Copy link
Copy Markdown
Contributor

fixes#55847

@typescript-botTypeScript Bot (typescript-bot) added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Sep 25, 2023
@jakebailey

Copy link
Copy Markdown
Member

This looks good to me (having touched this recently), but:

TypeScript Bot (@typescript-bot) test top200
TypeScript Bot (@typescript-bot) user test this
TypeScript Bot (@typescript-bot) run dt
TypeScript Bot (@typescript-bot) perf test this
TypeScript Bot (@typescript-bot) pack this

@typescript-bot

TypeScript Bot (typescript-bot) commented Sep 25, 2023

Copy link
Copy Markdown
Contributor

Heya Jake Bailey (@jakebailey), I've started to run the parallelized Definitely Typed test suite on this PR at 9f56c7f. You can monitor the build here.

Update: The results are in!

@typescript-bot

TypeScript Bot (typescript-bot) commented Sep 25, 2023

Copy link
Copy Markdown
Contributor

Heya Jake Bailey (@jakebailey), I've started to run the tarball bundle task on this PR at 9f56c7f. You can monitor the build here.

@typescript-bot

TypeScript Bot (typescript-bot) commented Sep 25, 2023

Copy link
Copy Markdown
Contributor

Heya Jake Bailey (@jakebailey), I've started to run the diff-based user code test suite on this PR at 9f56c7f. You can monitor the build here.

Update: The results are in!

@typescript-bot

TypeScript Bot (typescript-bot) commented Sep 25, 2023

Copy link
Copy Markdown
Contributor

Heya Jake Bailey (@jakebailey), I've started to run the regular perf test suite on this PR at 9f56c7f. You can monitor the build here.

Update: The results are in!

@typescript-bot

TypeScript Bot (typescript-bot) commented Sep 25, 2023

Copy link
Copy Markdown
Contributor

Heya Jake Bailey (@jakebailey), I've started to run the diff-based top-repos suite on this PR at 9f56c7f. You can monitor the build here.

Update: The results are in!

@typescript-bot

TypeScript Bot (typescript-bot) commented Sep 25, 2023

Copy link
Copy Markdown
Contributor

Hey Jake Bailey (@jakebailey), 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/157926/artifacts?artifactName=tgz&fileId=1FA9231F21A39E8A58C48819B07BF08D74C3576968C20B4DB594B040867ABB8802&fileName=/typescript-5.3.0-insiders.20230925.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-55856-6".;

@typescript-bot

Copy link
Copy Markdown
Contributor

Jake Bailey (@jakebailey) Here are the results of running the user test suite comparing main and refs/pull/55856/merge:

There were infrastructure failures potentially unrelated to your change:

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

Otherwise...

Everything looks good!

@typescript-bot

Copy link
Copy Markdown
Contributor

Jake Bailey (@jakebailey)
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 used294,974k (± 0.01%)294,952k (± 0.01%)~294,908k294,991kp=0.230 n=6
Parse Time2.61s (± 0.32%)2.61s (± 0.71%)~2.60s2.65sp=0.607 n=6
Bind Time0.84s (± 1.23%)0.83s (± 0.98%)~0.83s0.85sp=0.595 n=6
Check Time8.06s (± 0.35%)8.06s (± 0.24%)~8.03s8.08sp=1.000 n=6
Emit Time7.04s (± 0.45%)7.06s (± 0.53%)~7.00s7.09sp=0.260 n=6
Total Time18.56s (± 0.22%)18.57s (± 0.24%)~18.51s18.63sp=0.748 n=6
Compiler-Unions - node (v18.15.0, x64)
Memory used192,129k (± 1.25%)191,670k (± 1.23%)~190,687k196,485kp=0.173 n=6
Parse Time1.34s (± 0.61%)1.35s (± 0.86%)+0.01s (+ 1.12%)1.34s1.37sp=0.039 n=6
Bind Time0.73s (± 0.00%)0.73s (± 0.00%)~0.73s0.73sp=1.000 n=6
Check Time9.14s (± 0.72%)9.12s (± 0.59%)~9.03s9.18sp=0.873 n=6
Emit Time2.63s (± 0.56%)2.63s (± 0.40%)~2.61s2.64sp=0.805 n=6
Total Time13.84s (± 0.37%)13.83s (± 0.43%)~13.72s13.89sp=1.000 n=6
Monaco - node (v18.15.0, x64)
Memory used347,219k (± 0.01%)347,216k (± 0.01%)~347,173k347,248kp=0.873 n=6
Parse Time2.45s (± 0.42%)2.46s (± 0.36%)~2.45s2.47sp=0.273 n=6
Bind Time0.94s (± 0.00%)0.94s (± 0.00%)~0.94s0.94sp=1.000 n=6
Check Time6.88s (± 0.39%)6.85s (± 0.43%)~6.80s6.88sp=0.141 n=6
Emit Time4.02s (± 0.24%)4.02s (± 0.49%)~3.99s4.04sp=0.802 n=6
Total Time14.29s (± 0.25%)14.27s (± 0.18%)~14.24s14.30sp=0.168 n=6
TFS - node (v18.15.0, x64)
Memory used302,495k (± 0.01%)302,488k (± 0.01%)~302,468k302,523kp=0.297 n=6
Parse Time2.01s (± 0.97%)2.01s (± 0.68%)~1.99s2.03sp=0.567 n=6
Bind Time1.00s (± 0.41%)1.01s (± 1.32%)~1.00s1.03sp=0.462 n=6
Check Time6.26s (± 0.34%)6.24s (± 0.49%)-0.02s (- 0.40%)6.22s6.30sp=0.048 n=6
Emit Time3.55s (± 1.08%)3.52s (± 0.80%)~3.49s3.57sp=0.372 n=6
Total Time12.82s (± 0.55%)12.78s (± 0.27%)~12.74s12.83sp=0.466 n=6
material-ui - node (v18.15.0, x64)
Memory used470,449k (± 0.00%)470,450k (± 0.00%)~470,427k470,478kp=0.936 n=6
Parse Time2.56s (± 0.35%)2.57s (± 0.49%)~2.56s2.59sp=0.209 n=6
Bind Time0.99s (± 0.55%)0.99s (± 0.82%)~0.98s1.00sp=0.859 n=6
Check Time16.60s (± 0.19%)16.59s (± 0.60%)~16.50s16.73sp=0.422 n=6
Emit Time0.00s (± 0.00%)0.00s (± 0.00%)~0.00s0.00sp=1.000 n=6
Total Time20.16s (± 0.17%)20.15s (± 0.53%)~20.05s20.31sp=0.520 n=6
xstate - node (v18.15.0, x64)
Memory used512,556k (± 0.02%)512,514k (± 0.01%)~512,441k512,575kp=0.378 n=6
Parse Time3.27s (± 0.12%)3.27s (± 0.26%)~3.26s3.28sp=0.285 n=6
Bind Time1.55s (± 0.33%)1.55s (± 0.48%)~1.54s1.56sp=0.241 n=6
Check Time2.83s (± 0.49%)2.84s (± 0.79%)~2.80s2.86sp=0.745 n=6
Emit Time0.08s (± 4.99%)0.08s (± 9.21%)~0.07s0.09sp=1.000 n=6
Total Time7.73s (± 0.19%)7.73s (± 0.26%)~7.71s7.75sp=0.809 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

tsserver

Comparison Report - baseline..pr
MetricbaselineprDeltaBestWorstp-value
Compiler-UnionsTSServer - node (v18.15.0, x64)
Req 1 - updateOpen2,350ms (± 0.93%)2,350ms (± 1.24%)~2,324ms2,398msp=0.748 n=6
Req 2 - geterr5,371ms (± 1.62%)5,375ms (± 1.52%)~5,257ms5,448msp=0.810 n=6
Req 3 - references329ms (± 1.50%)327ms (± 0.57%)~325ms330msp=0.371 n=6
Req 4 - navto275ms (± 0.78%)276ms (± 1.11%)~272ms281msp=1.000 n=6
Req 5 - completionInfo count1,356 (± 0.00%)1,356 (± 0.00%)~1,3561,356p=1.000 n=6
Req 5 - completionInfo84ms (± 8.13%)86ms (± 7.12%)~76ms90msp=0.652 n=6
CompilerTSServer - node (v18.15.0, x64)
Req 1 - updateOpen2,461ms (± 1.60%)2,466ms (± 1.18%)~2,421ms2,495msp=1.000 n=6
Req 2 - geterr4,153ms (± 1.94%)4,141ms (± 1.92%)~4,062ms4,231msp=0.423 n=6
Req 3 - references336ms (± 1.03%)338ms (± 1.28%)~333ms343msp=0.328 n=6
Req 4 - navto283ms (± 0.43%)283ms (± 0.18%)~283ms284msp=0.351 n=6
Req 5 - completionInfo count1,518 (± 0.00%)1,518 (± 0.00%)~1,5181,518p=1.000 n=6
Req 5 - completionInfo77ms (± 7.19%)79ms (± 7.50%)~75ms87msp=0.285 n=6
xstateTSServer - node (v18.15.0, x64)
Req 1 - updateOpen2,596ms (± 0.41%)2,600ms (± 0.44%)~2,579ms2,608msp=0.260 n=6
Req 2 - geterr1,706ms (± 1.55%)1,674ms (± 1.68%)~1,640ms1,721msp=0.093 n=6
Req 3 - references121ms (± 6.58%)113ms (± 8.62%)~106ms126msp=0.106 n=6
Req 4 - navto360ms (± 0.76%)360ms (± 0.49%)~358ms363msp=0.802 n=6
Req 5 - completionInfo count2,071 (± 0.00%)2,071 (± 0.00%)~2,0712,071p=1.000 n=6
Req 5 - completionInfo306ms (± 1.62%)305ms (± 1.90%)~297ms313msp=0.748 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 time151.89ms (± 0.15%)151.98ms (± 0.18%)+0.09ms (+ 0.06%)150.85ms155.36msp=0.005 n=600
tsserver-startup - node (v18.15.0, x64)
Execution time227.62ms (± 0.18%)227.38ms (± 0.15%)-0.23ms (- 0.10%)225.78ms232.51msp=0.000 n=600
tsserverlibrary-startup - node (v18.15.0, x64)
Execution time229.09ms (± 0.19%)229.27ms (± 0.18%)+0.18ms (+ 0.08%)227.65ms235.68msp=0.000 n=600
typescript-startup - node (v18.15.0, x64)
Execution time228.88ms (± 0.22%)228.58ms (± 0.15%)-0.30ms (- 0.13%)227.07ms234.10msp=0.000 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 Jake Bailey (@jakebailey), 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

Jake Bailey (@jakebailey) Here are the results of running the top-repos suite comparing main and refs/pull/55856/merge:

Everything looks good!

@sankantsu

Godai Takashina (sankantsu) commented Sep 26, 2023

Copy link
Copy Markdown

Thank you for creating PR!

It seems still fails in some (very artificial) examples...

type E<S> = Lowercase<`f${S & string}` & `${S & string}f`>
>E : Lowercase<`f${S & string}` & `${S & string}f`>
type F = E<""> extends "f" ? 1 : 0
>F : 1
type G<S> = E<S> extends "f" ? 1 : 0
>G : 0
let x5: G<""> = 1;
>x5 : 0
>1 : 1

E<""> is "f", so G<""> should be 1

Playground link (v5.0.4)

@Andarist

Copy link
Copy Markdown
ContributorAuthor

Ah, ye - I see why it might fail. I'll try to improve the fix in a moment to handle more crazy scenarios like this recursively.

@typescript-botTypeScript 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 Sep 27, 2023
Comment threadsrc/compiler/checker.ts Outdated
function isPatternLiteralPlaceholderType(type: Type): boolean {
function isPatternLiteralPlaceholderType(type: Type, ignoreGenericIntersections = false): boolean {
if (type.flags & TypeFlags.Intersection) {
return some((type as IntersectionType).types, t => !!(t.flags & (TypeFlags.Literal | TypeFlags.Null | TypeFlags.Undefined)) || isPatternLiteralPlaceholderType(t));

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.

I think this entire fix can be simplified to simply adding a check that the type isn't generic:

return!isGenericType(type)&&some(...);

Generic types should never be classified as placeholders since upon instantiation they may become something completely different.

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.

Oh, that's cool! Thanks for the tip. I was worried that addSpans would fail if I did something like this. It seems that (somewhat confusingly) isGenericIndexType already returns true for an intersection like this so addSpans is covered.

@jakebailey

Copy link
Copy Markdown
Member

LGTM but just going to double check:

TypeScript Bot (@typescript-bot) test top200
TypeScript Bot (@typescript-bot) user test this
TypeScript Bot (@typescript-bot) run dt
TypeScript Bot (@typescript-bot) perf test this faster

@typescript-bot

TypeScript Bot (typescript-bot) commented Sep 29, 2023

Copy link
Copy Markdown
Contributor

Heya Jake Bailey (@jakebailey), I've started to run the diff-based top-repos suite on this PR at 5d29c23. You can monitor the build here.

Update: The results are in!

@typescript-bot

TypeScript Bot (typescript-bot) commented Sep 29, 2023

Copy link
Copy Markdown
Contributor

Heya Jake Bailey (@jakebailey), I've started to run the tsc-only perf test suite on this PR at 5d29c23. You can monitor the build here.

Update: The results are in!

@typescript-bot

TypeScript Bot (typescript-bot) commented Sep 29, 2023

Copy link
Copy Markdown
Contributor

Heya Jake Bailey (@jakebailey), I've started to run the parallelized Definitely Typed test suite on this PR at 5d29c23. You can monitor the build here.

Update: The results are in!

@typescript-bot

TypeScript Bot (typescript-bot) commented Sep 29, 2023

Copy link
Copy Markdown
Contributor

Heya Jake Bailey (@jakebailey), I've started to run the diff-based user code test suite on this PR at 5d29c23. You can monitor the build here.

Update: The results are in!

@typescript-bot

Copy link
Copy Markdown
Contributor

Jake Bailey (@jakebailey)
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 used294,998k (± 0.01%)295,000k (± 0.01%)~294,951k295,054kp=1.000 n=6
Parse Time2.63s (± 0.42%)2.63s (± 0.66%)~2.60s2.65sp=0.365 n=6
Bind Time0.84s (± 1.06%)0.84s (± 1.06%)~0.83s0.85sp=1.000 n=6
Check Time8.08s (± 0.36%)8.06s (± 0.12%)~8.05s8.07sp=0.289 n=6
Emit Time7.03s (± 0.25%)7.04s (± 0.29%)~7.01s7.07sp=0.935 n=6
Total Time18.58s (± 0.17%)18.57s (± 0.12%)~18.55s18.61sp=0.747 n=6
Compiler-Unions - node (v18.15.0, x64)
Memory used192,089k (± 1.24%)192,597k (± 1.56%)~190,606k196,482kp=0.810 n=6
Parse Time1.35s (± 1.11%)1.35s (± 0.87%)~1.34s1.37sp=0.730 n=6
Bind Time0.73s (± 0.00%)0.73s (± 0.00%)~0.73s0.73sp=1.000 n=6
Check Time9.21s (± 0.65%)9.18s (± 0.17%)~9.15s9.19sp=0.683 n=6
Emit Time2.62s (± 0.54%)2.63s (± 0.62%)~2.61s2.65sp=0.568 n=6
Total Time13.92s (± 0.44%)13.88s (± 0.18%)~13.85s13.91sp=0.293 n=6
Monaco - node (v18.15.0, x64)
Memory used347,239k (± 0.00%)347,226k (± 0.01%)~347,204k347,248kp=0.229 n=6
Parse Time2.45s (± 0.36%)2.46s (± 0.42%)~2.44s2.47sp=0.273 n=6
Bind Time0.94s (± 0.43%)0.94s (± 0.00%)~0.94s0.94sp=0.405 n=6
Check Time6.89s (± 0.51%)6.88s (± 0.50%)~6.84s6.93sp=0.687 n=6
Emit Time4.03s (± 0.38%)4.03s (± 0.37%)~4.01s4.05sp=0.801 n=6
Total Time14.31s (± 0.26%)14.30s (± 0.28%)~14.26s14.35sp=0.466 n=6
TFS - node (v18.15.0, x64)
Memory used302,529k (± 0.01%)302,550k (± 0.01%)~302,519k302,582kp=0.336 n=6
Parse Time2.00s (± 1.32%)2.00s (± 0.82%)~1.98s2.02sp=0.807 n=6
Bind Time1.01s (± 1.08%)1.01s (± 0.51%)~1.00s1.01sp=0.670 n=6
Check Time6.27s (± 0.60%)6.26s (± 0.52%)~6.20s6.29sp=0.872 n=6
Emit Time3.54s (± 0.85%)3.55s (± 0.96%)~3.51s3.59sp=0.461 n=6
Total Time12.82s (± 0.31%)12.80s (± 0.50%)~12.74s12.89sp=0.520 n=6
material-ui - node (v18.15.0, x64)
Memory used470,489k (± 0.00%)470,484k (± 0.00%)~470,471k470,503kp=0.810 n=6
Parse Time2.57s (± 0.38%)2.57s (± 0.52%)~2.55s2.59sp=0.858 n=6
Bind Time0.99s (± 1.64%)1.00s (± 0.75%)~0.99s1.01sp=0.741 n=6
Check Time16.56s (± 0.32%)16.64s (± 0.48%)~16.56s16.78sp=0.066 n=6
Emit Time0.00s (± 0.00%)0.00s (± 0.00%)~0.00s0.00sp=1.000 n=6
Total Time20.12s (± 0.30%)20.21s (± 0.34%)~20.15s20.33sp=0.108 n=6
xstate - node (v18.15.0, x64)
Memory used512,548k (± 0.02%)512,580k (± 0.02%)~512,495k512,729kp=0.378 n=6
Parse Time3.26s (± 0.41%)3.27s (± 0.30%)~3.25s3.28sp=0.340 n=6
Bind Time1.55s (± 0.33%)1.55s (± 0.33%)~1.54s1.55sp=1.000 n=6
Check Time2.83s (± 1.15%)2.85s (± 1.03%)~2.82s2.90sp=0.293 n=6
Emit Time0.08s (± 0.00%)0.08s (± 5.21%)~0.07s0.08sp=0.405 n=6
Total Time7.72s (± 0.55%)7.74s (± 0.32%)~7.72s7.79sp=0.225 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

Jake Bailey (@jakebailey) Here are the results of running the user test suite comparing main and refs/pull/55856/merge:

There were infrastructure failures potentially unrelated to your change:

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

Otherwise...

Everything looks good!

@typescript-bot

Copy link
Copy Markdown
Contributor

Hey Jake Bailey (@jakebailey), 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

Jake Bailey (@jakebailey) Here are the results of running the top-repos suite comparing main and refs/pull/55856/merge:

Everything looks good!

@sandersn

Copy link
Copy Markdown
Member

Jake Bailey (@jakebailey)Anders Hejlsberg (@ahejlsberg) is this a fix intended for 5.3, or should we wait until 5.4?

@jakebailey

Copy link
Copy Markdown
Member

Probably meant for 5.3, not sure why we didn't merge it as we both approved

@sandersn
Nathan Shively-Sanders (sandersn) merged commit 41ebfbf into microsoft:mainOct 26, 2023
@microsoftMicrosoft (microsoft) locked as resolved and limited conversation to collaborators Oct 22, 2025
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

Archived in project

Development

Successfully merging this pull request may close these issues.

Intrinsic string mapping type with type parameters is incorrectly resolved in conditional types

6 participants

@Andarist@jakebailey@typescript-bot@sankantsu@sandersn@ahejlsberg