Skip to content

Pr issue 57087 - fix for relating (e.g. satisfies) function overloads to intersection specifications #57395

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

Closed
wants to merge 22 commits into from

Conversation

craigphicks
Copy link

@craigphicks craigphicks commented Feb 13, 2024

Usage Scenario:

Suppose an intersection type:

interface C {
  (x:1):"1";
  (x:2):"20";
  (x:number):number | "1" | "20";
};
interface B {
  (x:2):"2"
  (x:3):"30"
  (x:number):number | "2" | "30";
};
interface A {
  (x:3):"3"
  (x:1):"10"
  (x:number):number | "3" | "10";
};

Current behavior

Without this pull, in order to write an implementation, the only reliable error-free overload implementation and declaration requires concatenating all the declarations of the intersection type as follows:

function foo2(x:1):"1";
function foo2(x:2):"20";
function foo2(x:number):number;
function foo2(x:2):"2"
function foo2(x:3):"30"
function foo2(x:number):number;
function foo2(x:3):"3"
function foo2(x:1):"10"
function foo2(x:number):number;
function foo2(x:number){
  if (x===1) return "1";
  if (x===2) return "2";
  if (x===3) return "3";
  // (*) These runtime-unused extra lines need to be added 
  // to make the implementation compatible with the overload signature
  if (x===1) return "10";
  if (x===2) return "20";
  if (x===3) return "30";
  return x;
}

That has disadvantages:

  • The large number of overloads in the declaration imposes a workload on the ts compiler downstream.
  • It is not user friendly.
  • The compiler also requires runtime-unused extra lines need to be added to make the implementation compatible with the overload signature.

New Behavior

With this pull the following declaration and implementation are allowed instead:

function foo1(x:1):"1";
function foo1(x:2):"2";
function foo1(x:3):"3";
function foo1(x:number):number;
function foo1(x:number){
  if (x===1) return "1";
  if (x===2) return "2";
  if (x===3) return "3";
  return x;
}

Implementation

Where

The function checkOverloadsRelatedToIntersection is called only when

  • (target.flags & TypeFlags.Intersection) and
  • typeRelatedToEachType(source,target) returned Ternary.False
  • the number of source signatures is >1.

Therefore, it only affect cases which were previously rejected.

Algorithm

Algorithm used within checkOverloadsRelatedToIntersection:

Let s[i], i in 0...Ns-1 be the source overloads.

Let t[j], j in 0...Nt-1 be the target intersection member types.

Let t[j][k], k in 0...Ntj-1 be the target overloads in type t[j].

SourceDomainMatch(i):==
    For some j,k exists IdentitiyRelation(Parameters<s[i]>,Parameters<t[j][k]>)===true

SourceRangeMatch(i):==
    Let rt be the union of ReturnTypes<t[j][k]> for all j,k s.t. Parameters<s[i]> assignable to Parameters<t[j][k]>
    ReturnTypes<s[i]> assignable to rt

TargetDomainMatch(t[j,k]):==
    For some i exists IdentitiyRelation(Parameters<s[i]>,Parameters<t[j][k]>)===true

Passing conditions:
- For all i, SourceDomainMatch(i)===true
- For all i, SourceRangeMatch(i)===true
- For all j,k, TargetDomainMatch(t[j][k])===true

SourceDomainMatch checks that source domain maps into the target domain.
SourceRangeMatch checks that source range maps into the target range.
TargetDomainMatch checks that target domain maps into the source domain

Diff URL

Fixes #57112

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Feb 13, 2024
@typescript-bot
Copy link
Collaborator

The TypeScript team hasn't accepted the linked issue #57087. If you can get it accepted, this PR will have a better chance of being reviewed.

@craigphicks craigphicks marked this pull request as draft February 13, 2024 17:41
@craigphicks craigphicks changed the title Pr issue 57078 Pr issue 57087 - fix for relating (e.g. satisfies) function overloads to intersection specifications Feb 15, 2024
@craigphicks craigphicks marked this pull request as ready for review February 22, 2024 19:55
@RyanCavanaugh
Copy link
Member

@typescript-bot test this
@typescript-bot test top100
@typescript-bot user test this
@typescript-bot user test tsserver
@typescript-bot test tsserver top100
@typescript-bot run dt
@typescript-bot perf test this
@typescript-bot pack this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Feb 22, 2024

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Feb 22, 2024

Heya @RyanCavanaugh, I've started to run the diff-based user code test suite (tsserver) on this PR at 2d54894. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Feb 22, 2024

Heya @RyanCavanaugh, I've started to run the regular perf test suite on this PR at 2d54894. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Feb 22, 2024

Heya @RyanCavanaugh, I've started to run the parallelized Definitely Typed test suite on this PR at 2d54894. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Feb 22, 2024

Heya @RyanCavanaugh, I've started to run the diff-based top-repos suite (tsserver) on this PR at 2d54894. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Feb 22, 2024

Heya @RyanCavanaugh, I've started to run the diff-based user code test suite on this PR at 2d54894. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Feb 22, 2024

Hey @RyanCavanaugh, 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/159985/artifacts?artifactName=tgz&fileId=7AB40D8DBAA394D139B88F615EF71F015207AD8DB1D1B617E1361782B6C5F54C02&fileName=/typescript-5.5.0-insiders.20240222.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.5.0-pr-57395-9".;

@typescript-bot
Copy link
Collaborator

@RyanCavanaugh Here are the results of running the user test suite comparing main and refs/pull/57395/merge:

Everything looks good!

@typescript-bot
Copy link
Collaborator

@RyanCavanaugh
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,653k (± 0.01%) 295,692k (± 0.01%) +39k (+ 0.01%) 295,674k 295,728k p=0.037 n=6
Parse Time 2.66s (± 0.19%) 2.66s (± 0.28%) ~ 2.65s 2.67s p=0.241 n=6
Bind Time 0.83s (± 1.08%) 0.83s (± 0.99%) ~ 0.82s 0.84s p=0.550 n=6
Check Time 8.24s (± 0.30%) 8.33s (± 0.21%) +0.09s (+ 1.07%) 8.30s 8.35s p=0.005 n=6
Emit Time 7.10s (± 0.43%) 7.09s (± 0.25%) ~ 7.08s 7.12s p=0.935 n=6
Total Time 18.84s (± 0.15%) 18.91s (± 0.13%) +0.08s (+ 0.41%) 18.87s 18.93s p=0.007 n=6
Compiler-Unions - node (v18.15.0, x64)
Memory used 194,575k (± 1.69%) 192,644k (± 1.27%) ~ 191,617k 197,662k p=0.810 n=6
Parse Time 1.36s (± 1.39%) 1.36s (± 0.00%) ~ 1.36s 1.36s p=1.000 n=6
Bind Time 0.72s (± 0.00%) 0.72s (± 0.00%) ~ 0.72s 0.72s p=1.000 n=6
Check Time 9.36s (± 0.34%) 9.49s (± 0.58%) +0.13s (+ 1.39%) 9.43s 9.58s p=0.005 n=6
Emit Time 2.62s (± 0.59%) 2.62s (± 0.66%) ~ 2.59s 2.64s p=0.865 n=6
Total Time 14.06s (± 0.16%) 14.19s (± 0.40%) +0.13s (+ 0.95%) 14.13s 14.29s p=0.005 n=6
Monaco - node (v18.15.0, x64)
Memory used 347,488k (± 0.00%) 347,514k (± 0.01%) ~ 347,437k 347,541k p=0.066 n=6
Parse Time 2.48s (± 0.33%) 2.48s (± 0.97%) ~ 2.44s 2.51s p=0.801 n=6
Bind Time 0.93s (± 0.44%) 0.93s (± 0.44%) ~ 0.92s 0.93s p=1.000 n=6
Check Time 6.97s (± 0.23%) 7.07s (± 0.40%) +0.09s (+ 1.36%) 7.02s 7.10s p=0.004 n=6
Emit Time 4.05s (± 0.36%) 4.05s (± 0.60%) ~ 4.02s 4.09s p=0.871 n=6
Total Time 14.43s (± 0.16%) 14.53s (± 0.41%) +0.10s (+ 0.70%) 14.44s 14.59s p=0.016 n=6
TFS - node (v18.15.0, x64)
Memory used 302,856k (± 0.01%) 302,878k (± 0.01%) +22k (+ 0.01%) 302,850k 302,897k p=0.045 n=6
Parse Time 2.02s (± 0.99%) 2.01s (± 0.51%) ~ 2.00s 2.03s p=0.459 n=6
Bind Time 1.00s (± 0.52%) 1.00s (± 0.41%) ~ 0.99s 1.00s p=0.595 n=6
Check Time 6.36s (± 0.40%) 6.40s (± 0.41%) +0.04s (+ 0.63%) 6.36s 6.43s p=0.044 n=6
Emit Time 3.58s (± 0.35%) 3.57s (± 0.25%) ~ 3.56s 3.58s p=0.209 n=6
Total Time 12.96s (± 0.27%) 12.98s (± 0.11%) ~ 12.96s 13.00s p=0.227 n=6
material-ui - node (v18.15.0, x64)
Memory used 511,287k (± 0.00%) 511,299k (± 0.00%) ~ 511,258k 511,328k p=0.423 n=6
Parse Time 2.65s (± 0.48%) 2.65s (± 0.39%) ~ 2.64s 2.67s p=0.615 n=6
Bind Time 0.99s (± 0.41%) 0.99s (± 0.76%) ~ 0.98s 1.00s p=1.000 n=6
Check Time 17.29s (± 0.50%) 17.42s (± 0.24%) +0.13s (+ 0.72%) 17.34s 17.45s p=0.019 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 20.93s (± 0.38%) 21.07s (± 0.17%) +0.14s (+ 0.65%) 21.01s 21.10s p=0.008 n=6
mui-docs - node (v18.15.0, x64)
Memory used 2,293,609k (± 0.00%) 2,317,954k (± 0.00%) +24,345k (+ 1.06%) 2,317,919k 2,317,979k p=0.005 n=6
Parse Time 11.95s (± 0.87%) 11.99s (± 1.00%) ~ 11.87s 12.17s p=0.810 n=6
Bind Time 2.63s (± 0.20%) 2.64s (± 0.31%) +0.01s (+ 0.38%) 2.63s 2.65s p=0.050 n=6
Check Time 102.35s (± 0.66%) 102.84s (± 1.08%) ~ 101.64s 104.33s p=0.471 n=6
Emit Time 0.32s (± 1.28%) 0.32s (± 1.28%) ~ 0.31s 0.32s p=1.000 n=6
Total Time 117.25s (± 0.63%) 117.80s (± 0.88%) ~ 116.67s 119.17s p=0.336 n=6
self-build-src - node (v18.15.0, x64)
Memory used 2,413,592k (± 0.02%) 2,414,626k (± 0.02%) +1,034k (+ 0.04%) 2,414,006k 2,415,601k p=0.013 n=6
Parse Time 4.94s (± 0.71%) 4.93s (± 0.78%) ~ 4.88s 4.98s p=0.747 n=6
Bind Time 1.87s (± 0.66%) 1.88s (± 0.71%) ~ 1.86s 1.90s p=0.114 n=6
Check Time 33.71s (± 0.61%) 33.86s (± 0.35%) ~ 33.64s 33.99s p=0.173 n=6
Emit Time 2.71s (± 1.54%) 2.69s (± 1.15%) ~ 2.66s 2.74s p=0.332 n=6
Total Time 43.23s (± 0.52%) 43.37s (± 0.27%) ~ 43.23s 43.59s p=0.109 n=6
self-compiler - node (v18.15.0, x64)
Memory used 418,957k (± 0.01%) 419,270k (± 0.01%) +314k (+ 0.07%) 419,246k 419,313k p=0.005 n=6
Parse Time 2.79s (± 3.02%) 2.81s (± 0.90%) ~ 2.77s 2.84s p=0.872 n=6
Bind Time 1.13s (± 6.20%) 1.08s (± 0.00%) ~ 1.08s 1.08s p=0.176 n=6
Check Time 15.23s (± 0.22%) 15.30s (± 0.31%) +0.08s (+ 0.53%) 15.24s 15.38s p=0.012 n=6
Emit Time 1.13s (± 1.07%) 1.13s (± 1.20%) ~ 1.12s 1.15s p=0.934 n=6
Total Time 20.27s (± 0.21%) 20.33s (± 0.28%) ~ 20.24s 20.41s p=0.091 n=6
vscode - node (v18.15.0, x64)
Memory used 2,848,471k (± 0.00%) 2,848,483k (± 0.00%) ~ 2,848,442k 2,848,525k p=0.689 n=6
Parse Time 10.76s (± 0.31%) 10.76s (± 0.36%) ~ 10.71s 10.82s p=0.935 n=6
Bind Time 3.42s (± 0.51%) 3.44s (± 0.18%) ~ 3.43s 3.45s p=0.070 n=6
Check Time 60.70s (± 0.28%) 61.02s (± 0.36%) +0.33s (+ 0.54%) 60.64s 61.32s p=0.037 n=6
Emit Time 16.28s (± 0.27%) 16.24s (± 0.42%) ~ 16.18s 16.37s p=0.172 n=6
Total Time 91.16s (± 0.15%) 91.46s (± 0.28%) ~ 91.00s 91.72s p=0.065 n=6
webpack - node (v18.15.0, x64)
Memory used 396,913k (± 0.01%) 396,954k (± 0.02%) ~ 396,896k 397,080k p=0.689 n=6
Parse Time 3.15s (± 0.26%) 3.15s (± 0.48%) ~ 3.14s 3.17s p=0.740 n=6
Bind Time 1.39s (± 0.71%) 1.39s (± 0.60%) ~ 1.39s 1.41s p=0.273 n=6
Check Time 14.12s (± 0.19%) 14.16s (± 0.22%) +0.04s (+ 0.31%) 14.11s 14.19s p=0.043 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 18.66s (± 0.15%) 18.71s (± 0.25%) ~ 18.64s 18.76s p=0.072 n=6
xstate - node (v18.15.0, x64)
Memory used 513,425k (± 0.01%) 513,555k (± 0.02%) +130k (+ 0.03%) 513,446k 513,709k p=0.013 n=6
Parse Time 3.28s (± 0.37%) 3.28s (± 0.25%) ~ 3.27s 3.29s p=1.000 n=6
Bind Time 1.54s (± 0.33%) 1.54s (± 0.26%) ~ 1.54s 1.55s p=0.595 n=6
Check Time 2.87s (± 0.68%) 2.96s (± 1.27%) +0.10s (+ 3.37%) 2.91s 3.01s p=0.005 n=6
Emit Time 0.08s (± 6.19%) 0.08s (± 4.99%) ~ 0.08s 0.09s p=0.595 n=6
Total Time 7.77s (± 0.22%) 7.87s (± 0.40%) +0.10s (+ 1.29%) 7.82s 7.91s p=0.005 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,353ms (± 0.85%) 2,348ms (± 0.37%) ~ 2,339ms 2,364ms p=0.936 n=6
Req 2 - geterr 5,559ms (± 1.36%) 5,635ms (± 1.53%) ~ 5,553ms 5,754ms p=0.230 n=6
Req 3 - references 324ms (± 0.30%) 323ms (± 0.23%) ~ 322ms 324ms p=0.109 n=6
Req 4 - navto 276ms (± 1.24%) 276ms (± 0.81%) ~ 272ms 278ms p=0.869 n=6
Req 5 - completionInfo count 1,357 (± 0.00%) 1,357 (± 0.00%) ~ 1,357 1,357 p=1.000 n=6
Req 5 - completionInfo 86ms (± 8.40%) 84ms (± 8.44%) ~ 79ms 96ms p=0.869 n=6
CompilerTSServer - node (v18.15.0, x64)
Req 1 - updateOpen 2,489ms (± 0.74%) 2,487ms (± 0.88%) ~ 2,465ms 2,517ms p=0.936 n=6
Req 2 - geterr 4,173ms (± 1.82%) 4,197ms (± 1.38%) ~ 4,169ms 4,315ms p=0.229 n=6
Req 3 - references 337ms (± 1.44%) 334ms (± 0.49%) ~ 332ms 336ms p=0.376 n=6
Req 4 - navto 285ms (± 0.29%) 284ms (± 0.43%) ~ 282ms 285ms p=0.183 n=6
Req 5 - completionInfo count 1,519 (± 0.00%) 1,519 (± 0.00%) ~ 1,519 1,519 p=1.000 n=6
Req 5 - completionInfo 87ms (± 5.54%) 76ms (± 3.26%) 🟩-11ms (-12.12%) 74ms 79ms p=0.012 n=6
xstateTSServer - node (v18.15.0, x64)
Req 1 - updateOpen 2,618ms (± 0.30%) 2,620ms (± 0.43%) ~ 2,604ms 2,633ms p=0.810 n=6
Req 2 - geterr 1,739ms (± 2.46%) 1,761ms (± 2.48%) ~ 1,693ms 1,816ms p=0.298 n=6
Req 3 - references 127ms (± 1.07%) 121ms (± 9.00%) ~ 106ms 128ms p=0.361 n=6
Req 4 - navto 371ms (± 0.42%) 372ms (± 0.33%) ~ 370ms 373ms p=0.318 n=6
Req 5 - completionInfo count 2,079 (± 0.00%) 2,079 (± 0.00%) ~ 2,079 2,079 p=1.000 n=6
Req 5 - completionInfo 311ms (± 1.25%) 311ms (± 1.43%) ~ 306ms 317ms p=0.936 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 153.85ms (± 0.21%) 153.86ms (± 0.20%) ~ 152.55ms 156.73ms p=0.561 n=600
tsserver-startup - node (v18.15.0, x64)
Execution time 229.79ms (± 0.17%) 229.83ms (± 0.19%) ~ 228.50ms 238.64ms p=0.837 n=600
tsserverlibrary-startup - node (v18.15.0, x64)
Execution time 231.26ms (± 0.18%) 231.38ms (± 0.21%) +0.12ms (+ 0.05%) 229.80ms 242.86ms p=0.014 n=600
typescript-startup - node (v18.15.0, x64)
Execution time 231.69ms (± 0.19%) 231.79ms (± 0.19%) +0.10ms (+ 0.04%) 230.04ms 239.97ms p=0.001 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 @RyanCavanaugh, the results of running the DT tests are ready.
Everything looks the same!
You can check the log here.

@typescript-bot
Copy link
Collaborator

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

Something interesting changed - please have a look.

Details

Server exited prematurely with code unknown and signal SIGABRT

Server exited prematurely with code unknown and signal SIGABRT

Affected repos

calcom/cal.com Raw error text: RepoResults7/calcom.cal.com.rawError.txt in the artifact folder

Last few requests

{"seq":760,"type":"request","command":"completionInfo","arguments":{"file":"@PROJECT_ROOT@/apps/storybook/postcss.config.js","line":11,"offset":30,"includeExternalModuleExports":false,"triggerKind":1}}
{"seq":761,"type":"request","command":"completionInfo","arguments":{"file":"@PROJECT_ROOT@/apps/storybook/postcss.config.js","line":11,"offset":39,"includeExternalModuleExports":false,"triggerKind":2,"triggerCharacter":" "}}
{"seq":762,"type":"request","command":"updateOpen","arguments":{"changedFiles":[],"closedFiles":["@PROJECT_ROOT@/apps/api/pages/api/webhooks/[id]/_patch.ts"],"openFiles":[]}}
{"seq":763,"type":"request","command":"updateOpen","arguments":{"changedFiles":[],"closedFiles":[],"openFiles":[{"file":"@PROJECT_ROOT@/apps/swagger/lib/snippets.js","projectRootPath":"@PROJECT_ROOT@"}]}}

Repro steps

  1. git clone https://github.com/calcom/cal.com --recurse-submodules
  2. In dir cal.com, run git reset --hard 95d5824ba9b372dd2cda4ea3554631d3e9170a45
  3. In dir cal.com, run yarn install --no-immutable --mode=skip-build
  4. Back in the initial folder, download RepoResults7/calcom.cal.com.replay.txt from the artifact folder
  5. npm install --no-save @typescript/server-replay
  6. npx tsreplay ./cal.com ./calcom.cal.com.replay.txt path/to/tsserver.js
  7. npx tsreplay --help to learn about helpful switches for debugging, logging, etc

Server exited prematurely with code unknown and signal SIGABRT

Server exited prematurely with code unknown and signal SIGABRT

Affected repos

backstage/backstage Raw error text: RepoResults8/backstage.backstage.rawError.txt in the artifact folder

Last few requests

{"seq":3321,"type":"request","command":"completionInfo","arguments":{"file":"@PROJECT_ROOT@/packages/create-app/src/lib/versions.ts","line":139,"offset":4,"includeExternalModuleExports":false,"triggerKind":1}}
{"seq":3322,"type":"request","command":"references","arguments":{"file":"@PROJECT_ROOT@/packages/create-app/src/lib/versions.ts","line":141,"offset":4}}
{"seq":3323,"type":"request","command":"updateOpen","arguments":{"changedFiles":[],"closedFiles":["@PROJECT_ROOT@/packages/core-plugin-api/src/apis/system/ApiRef.ts"],"openFiles":[]}}
{"seq":3324,"type":"request","command":"updateOpen","arguments":{"changedFiles":[],"closedFiles":[],"openFiles":[{"file":"@PROJECT_ROOT@/packages/create-app/templates/default-app/packages/app/e2e-tests/app.test.ts","projectRootPath":"@PROJECT_ROOT@"}]}}

Repro steps

  1. git clone https://github.com/backstage/backstage --recurse-submodules
  2. In dir backstage, run git reset --hard 8cc5dd9d299ecc974c9f2b1dd9dc5ce0c6ab7a3d
  3. Install packages (exact steps are below, but it might be easier to follow the repo readme)
    1. In dir backstage/microsite, run yarn install --no-immutable --mode=skip-build
    2. In dir backstage, run yarn install --no-immutable --mode=skip-build
    3. In dir backstage/storybook, run yarn install --no-immutable --mode=skip-build
  4. Back in the initial folder, download RepoResults8/backstage.backstage.replay.txt from the artifact folder
  5. npm install --no-save @typescript/server-replay
  6. npx tsreplay ./backstage ./backstage.backstage.replay.txt path/to/tsserver.js
  7. npx tsreplay --help to learn about helpful switches for debugging, logging, etc

@craigphicks
Copy link
Author

@RyanCavanaugh - I guess this means I need to download the repos calcom/cal.com and/or backstate/backstage to confirm/recreate the problem - is that correct?

@jakebailey
Copy link
Member

Expand out the comment a few times and you'll get exact instructions on how to reproduce each.

@craigphicks
Copy link
Author

craigphicks commented Feb 23, 2024

@RyanCavanaugh @jakebailey

Re: the cal.com report

  1. After setting up according to the instructions the code in .../cal.com/node_modules/typescript/lib/tsserver.js does not include the changes in this pull Pr issue 57087 - fix for relating (e.g. satisfies) function overloads to intersection specifications #57395
  2. However, the reported error can be reliably reproduced using tsreplay as described in the instructions.
  3. Changing the hardcoded value in tsreplay giving the memory size for tsserver from 4096 to 8192 the error reliably disappears.

This is the output from ps when --max-old-space-size=

4096, reliably failing with final Exited unexpectedly with signal SIGABRT

node /workspaces/ts+dt/node_modules/.bin/tsreplay ./cal.com ./RepoResults7/calcom.cal.com.replay.txt cal.com/node_modules/typescript/lib/tsserver.js
usr/local/bin/node --max-old-space-size=4096 --expose-gc /workspaces/ts+dt/cal.com/node_modules/typescript/lib/tsserver.js --disableAutomaticTypingAcquisition

8192, reliably passing with final 999999 exit

node /workspaces/ts+dt/node_modules/.bin/tsreplay ./cal.com ./RepoResults7/calcom.cal.com.replay.txt cal.com/node_modules/typescript/lib/tsserver.js
usr/local/bin/node --max-old-space-size=8192 --expose-gc /workspaces/ts+dt/cal.com/node_modules/typescript/lib/tsserver.js --disableAutomaticTypingAcquisition

In the non-failing case, looking at system memory usage, it rises nearly monotonically with time to increase by 4.4 GiB.

I'll follow up by checking the other report too.

@craigphicks
Copy link
Author

craigphicks commented Feb 23, 2024

Re: The backstage error report:

  • (1) The instruction specified path path/to/tsserver.js has some ambiguity.

There are 4 tsserver.js files in the project:

./node_modules/typescript/lib/tsserver.js
./node_modules/@microsoft/api-extractor/node_modules/typescript/lib/tsserver.js
./microsite/node_modules/typescript/lib/tsserver.js
./storybook/node_modules/typescript/lib/tsserver.js

Of those,

./node_modules/@microsoft/api-extractor/node_modules/typescript/lib/tsserver.js
./storybook/node_modules/typescript/lib/tsserver.js

differ from ./node_modules/typescript/lib/tsserver.js, while

./microsite/node_modules/typescript/lib/tsserver.js

is the same.

I have assumed that

./node_modules/typescript/lib/tsserver.js

is the one to use.

  • (2) However, none of those tsserver.js files contain the text checkOverloadsRelatedToIntersection which would be there if pull request 57395 had been merged.

  • (3) Just as in my previous post, increasing tsreplay memory from 4GB to 8GB prevented the error from happening.

  • (4) Differently from the report in the previous post, there were some ups and down in memory usage (not a monotonic increase) before the error.

@jakebailey
Copy link
Member

@typescript-bot test top200

@typescript-bot
Copy link
Collaborator

typescript-bot commented Feb 24, 2024

Heya @jakebailey, I've started to run the diff-based top-repos suite on this PR at 2d54894. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

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

Everything looks good!

@craigphicks
Copy link
Author

@jakebailey - I am grateful and confused. I will look further into the SIGABRT examples.

@jakebailey
Copy link
Member

I would doubt that they are new in this PR; the server tests can be a little flaky.

@sandersn sandersn self-assigned this Feb 27, 2024
@sandersn sandersn requested review from sandersn and jakebailey and removed request for jakebailey February 27, 2024 19:16


/**
* The following function ft3 should fail. However, it currently does not
Copy link
Member

Choose a reason for hiding this comment

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

this is a half nit, but for comments in test files, I would avoid using language that includes "currently" or "new code", just because it'll end up out of date at some point. If there's a specific theory to these, then explaining them is alright, but the comments seem sorta speculative (like they should be review comment threads).

) {
if (
source.flags & TypeFlags.Object && getSignaturesOfType(source, SignatureKind.Call).length > 1
// && target.flags & TypeFlags.Object && getSignaturesOfType(target0, SignatureKind.Call).length > 1 // already known to be intersection type
Copy link
Member

Choose a reason for hiding this comment

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

This is commented out; I would not include commented out code unless it's explicitly trying to explain something (like in a comment above about why target isn't checked, or, assert it or something).

Copy link
Author

Choose a reason for hiding this comment

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

Must fix.

@jakebailey
Copy link
Member

Didn't realize this wasn't accepted; will look if the feature is okay'd.

@jakebailey jakebailey marked this pull request as draft February 27, 2024 19:32
@craigphicks
Copy link
Author

craigphicks commented Feb 28, 2024

This test case doesn't gets failed by the original code and doesn't get passed to the new function in the pull (which would pass it):

interface A {
    f(x:"a",y:string):1;
    f(x:"b",y:string):1;
    f(x:"c",y:string):1;
    f(x:"d",y:string):1;
    f(x:"e",y:string):1;
    f(x:"f",y:string):1;
};

interface B {
    f(x:"a",y:string):2;
    f(x:"b",y:string):2;
    f(x:"c",y:string):2;
    f(x:"d",y:string):2;
    f(x:"e",y:string):2;
    f(x:"f",y:string):2;
};
(0 as any as A) satisfies A&B;

So I have to check this before proceeding further.

@sandersn
Copy link
Member

sandersn commented Apr 2, 2025

@craigphicks Is this PR worth keeping open while waiting for us to have time to discuss the original issue? It's out of date with main now, but it might still be useful if you want to run top400 or other tests.

@sandersn sandersn closed this Apr 30, 2025
@github-project-automation github-project-automation bot moved this from Waiting on author to Done in PR Backlog Apr 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

A function overload that is mistakenly unassignable to an intersection type.
5 participants