-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[BUG] Type instantiation is excessively deep and possibly infinite on latest TypeScript 4.5 #715
Comments
Are there any known workarounds? Besides not being able to upgrade to v4.5 I suspect that this might be the underlying performance problem responsible for an extra ~5seconds of type-checking per compile in my current project. |
It's possible to use TS until 4.5.0-dev.20210930 (included): npm add -D typescript@4.5.0-dev.20210930 The problem was caused by an internal refactoring of typescript (TS PR 41821), before that it was working (for me) perfectly fine, even in large projects. |
My understanding was that the refactoring surfaced these problems - it didn't actually introduce the underlying problem. In other words, this is not a Typescript bug, it's a feature. It was/is also "working" for me in a fairly large project (total number of files processed per-compile is >1300), but we're having some pretty nasty Typescript performance issues which I've spent hours trying to debug. All that I've been able to deduce is that Zod seems to be at the heart of that problem. When I remove it, it cuts compile time in half and the total memory usage (as shown by |
Struggled with this for a solid day and it ended up being a one-line fix in Should be working with |
That's a good news! By the way, the behavior of TS is strange here: type F<T> = {} & (
T extends [any, ...any[]]
? { [K in keyof T]?: F<T[K]> }
: T extends any[]
? F<T[number]>[]
: T extends { [K: string]: any }
? { [K in keyof T]?: F<T[K]> }
: { x: unknown }
);
function f<T = any>() {
return undefined! as F<T>;
}
export function g() {
return f() as F<any>;
} Changing anything removes the error:
To me it looks like an problematic edge case of TS 4.5, with a really low probability of being discovered... |
Great minimal repro of the problem. I'm pretty sure we're the only people who will every be affected by it 😛 |
My thoughts exactly :))) I posted this as a TS issue: microsoft/TypeScript#46500 And indeed, it's confirmed:
|
There is a new issue that appeared in TypeScript 4.5.0-dev.20211001 and exists until now.
To reproduce the error:
TypeScript output:
It affects the latest Zod (3.10.1), and also any other 3.x version. The issue appeared in microsoft/TypeScript#41821 (producing a memory error), and later a check was added in microsoft/TypeScript#46326 to prevent the infinite loop and give a meaningful message.
This is the same issue as #689 except that now we have an error message.
Demo code: https://github.com/mmvsk/zod-issue-715
The text was updated successfully, but these errors were encountered: