Repository: TypeScript
Issue: Use of intersection type leads to extremely slow typecheck times
Labels: Needs More Info

### 🔎 Search Terms

"intersection", "performance", "typecheck", "subtype", "time"

### 🕗 Version & Regression Information

- This is the behavior in every version I tried, and I reviewed the FAQ for entries about performance



### ⏯ Playground Link

_No response_

### 💻 Code

```ts
// Your code here
```


### 🙁 Actual behavior

I have a pretty complicated library: https://github.com/xixixao/convex-ents (it's similar to Prisma)

(I'm gonna describe the issue in-situ, because essentially the whole library is involved to get the times I'm observing)

All the code I'll mention is in this file: https://github.com/xixixao/convex-ents/blob/edgebitfaster-more-deduped/src/functions.ts

In it I have two intersection types, `Ent` and `EntWriter`. I have to use an intersection, because I want to add methods to a POJO (I do this via an intersection between a class and a Record type).

One type should be a subtype of the other (`EntWriter` should be a subtype of `Ent`).

The types have a method `edge` (from the class in the intersection), which returns a conditional type (`PromiseEdge` and `PromiseEdgeWriter` respectively), which results in other complicated types, but the subtyping relationship holds.

The library code typechecks fine, but the issue arises when the user of the library tries to assert that `EntWriter<>` is indeed a subtype of `Ent`:
```ts
const x: Ent<"sometable"> = someEntWriter;
```

Now TypeScript goes and tries to check the subtyping relationship, starting with the intersection, walking to the conditionals, and to all their branches, and to all the methods of those types, etc. It took minutes.

I can observe the slowdown by reverting `PromiseEdgeWriter` to match `PromiseEdge` exactly, and then changing one branch at a time.

After reading the performance wiki and getting a trace and going through the types, I have optimized this somewhat. I have pulled out the conditional logic into a type that is reused (see `PromiseEdgeResult`). This helped a lot, but the typechecking still takes 12 seconds instead of sub-second without this `edge` type change.

I tried pulling out the intersection to a helper type as well (`EntBase`) but this had no impact. It seems that the intersection is "inlined"?


### 🙂 Expected behavior

What I think would help me is if:

A subtype of B
X' = X<A, C>
X'' = X<B, C>
implied that X' subtype of X''
even when X<T, U> = T & U

But this doesn't seem to be what the typechecker actually assumes? (probably because intersection merged properties as per wiki)

But could I hint somehow to the compiler to not go through this whole huge reasoning chain? I know that EntWriter is subtype of Ent when their generic arguments are the same.

The intersection types themselves are ok, but it's the interplay with the two classes. The slowdown is from the `edge` method being checked. So alternatively I'd like to tell TypeScript: "Hey, this method does correctly override the parent class's method, you don't need to check that if the generic arguments to it are the same"

### Additional information about the issue

_No response_