Recursive type: Type instantiation is excessively deep and possibly infinite.
See original GitHub issueI’m running into a problem creating a parser for a fairly simple recursive type. The following errors with Type instantiation is excessively deep and possibly infinite. TS2589
:
type V = [V] | "Null"
const V : z.ZodSchema<V> = z.lazy(() =>
z.union([
z.tuple([V]),
z.literal("Null")
]))
However a loosely similar type works fine:
interface V {
a: [V]
}
const V : z.ZodSchema<V> = z.lazy(() =>
z.object({
a: z.tuple([V])
})
)
The use of the Tuple is significant, using an array works fine for both.
I’d be willing to work on a pr but I had a poke around and didn’t get far in finding out what causes this, if you have any tips on what might be causing it I can take another look.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:9 (2 by maintainers)
Top Results From Across the Web
Why am I getting "Type instantiation is excessively deep and ...
The AllModuleActions<M> type is recursive in a way that the compiler cannot ... Type instantiation is excessively deep and possibly infinite.
Read more >4.6.2 regression: `Type instantiation is excessively deep and ...
Actual behavior ... Type instantiation is excessively deep and possibly infinite. at the ${P}.${DeepKeys<T[P]>} snippet. Expected behavior.
Read more >Documentation - TypeScript 4.5
TypeScript often needs to gracefully fail when it detects possibly infinite recursion, or any type expansions that can take a long time and...
Read more >Type instantiation is excessively deep and possibly infinite ...
Getting `Type instantiation is excessively deep and possibly infinite` errors whenever I pass MongoClient as a parameter in my code after ...
Read more >DefinitelyTyped/DefinitelyTyped - Gitter
It doesn't seem like the team at TS ever uses recursive types. ... the lint tests I still got n Type instantiation is...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
A similar error occurs when TypeScript version is 4.3 or higher.
I’m using TypeScrip version 4.1.5 now because I don’t get this error with the version. Next.js recommends TypeScript version 4.3.2 or higher, so if anyone knows how to avoid this error, please let me know.
@takahash
This sounds similar to an issue where you might have two different versions of
zod
installed? Are you exportingC
into a different project that might have a different version ofzod
also declared?