Post

Investigating a TypeScript caching issue that could have a *massive* impact for validators like ArkType, Zod and Valibot. For projects that heavily rely on schema inference like tRPC, fixing this could have a bigger impact than tsgo. Trigger Warning: O(3^N)

2 reposts45 likes

You're totally right, this particular case seems to have been introduced in 5.5! Unfortunately, I think this was never really understood and the `merge` example just happened to work before then because none of the real world examples improve.

Intersections including mapped types are lazily evaluated, but in many cases like this one, it appears they are never properly cached. Every time the type is referenced, it is re-instantiated, leading to O(3^N) scaling☠️

Would be very curious to learn how you go about investigating this and fixing it; maybe on here or in a blog post? I've been dealing with some mysterious excessively deep errors and it's usually rather difficult to narrow down the cause.