I have a pretty complicated library: https://github.com/xixixao/convex-ents (it's similar to Prisma)
(I'm gonna just describe the issue in-situ, as it's pretty complicated to pull it out into the playground)
All the code I'll mention is in this file: https://github.com/xixixao/convex-ents/blob/c6e88cf7c539fc452f061f5f26c28565be3e2bf2/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:
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 can take minutes.
I can observe the slowdown by reverting PromiseEdgeWriter to match PromiseEdge exactly, and then changing one branch at a time.
I'm afraid that this is a fundamental limitation of this setup, but I'm curious whether anyone here has any tips on what to try. I already tried:
- Making the result types of the branches in
PromiseEdgeWriterbe sub-interfaces of those inPromiseEdge, and only override methods (include thethenmethod to change the Promise type). - Making the result types of the branches generic (which is similar but doesn't require overriding the
thenmethod)
Thanks!