question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Type instantiation is excessively deep and possibly infinite on latest TypeScript 4.5

See original GitHub issue

There is a new issue that appeared in TypeScript 4.5.0-dev.20211001 and exists until now.

To reproduce the error:

npm init -y
npm add zod
npm add -D typescript@next
echo 'import { z } from "zod";' > main.ts
echo '{"compilerOptions":{"lib":["es2020"]},"include":["main.ts"]}' > tsconfig.json
npx tsc -p .

TypeScript output:

node_modules/zod/lib/helpers/partialUtil.d.ts:4:29 - error TS2589: Type instantiation is excessively deep and possibly infinite.

4         [k in keyof Shape]: ZodOptional<DeepPartial<Shape[k]>>;
                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Found 1 error.

It affects the latest Zod (3.10.1), and also any other 3.x version. The issue appeared in https://github.com/microsoft/TypeScript/pull/41821 (producing a memory error), and later a check was added in https://github.com/microsoft/TypeScript/pull/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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
colinhackscommented, Oct 24, 2021

Great minimal repro of the problem. I’m pretty sure we’re the only people who will every be affected by it 😛

0reactions
maxmvskcommented, Oct 25, 2021

My thoughts exactly 😃))

I posted this as a TS issue: https://github.com/microsoft/TypeScript/issues/46500

And indeed, it’s confirmed:

Yeah, that isn’t right. The issue here is that we bypass caching of relations for small unions and intersections, but that bypass also causes us to loose a check for deeply nested types that would have stopped the recursion. It used to not matter, but after #41821 it does. We need to revise our logic such that we can bypass caching but still check for deep nesting.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TS 4.5 type instantiation is excessively deep and possibly ...
Bug Report There seem to be an issue with a very specific edge case: type F ... TS 4.5 type instantiation is excessively...
Read more >
Why am I getting "Type instantiation is excessively deep and ...
You'll notice in the Playground link that action has the error: "Type instantiation is excessively deep and possibly infinite". I assume this is ......
Read more >
Documentation - TypeScript 4.5
TypeScript 4.5 introduces a new utility type called the Awaited type. ... error: Type instantiation is excessively deep and possibly infinite.
Read more >
TypeScript. Type instantiation is excessively deep ... - Ilya Zykin
Not always I know how to manage them. One of the messages is: Type instantiation is excessively deep and possibly infinite.ts(2589). Visual Studio...
Read more >
Announcing TypeScript 4.5 RC - Microsoft Developer Blogs
TypeScript 4.5 introduces a new utility type called the Awaited type. ... Type instantiation is excessively deep and possibly infinite. type ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found