When working in a monorepo/workspace project, I can trigger the following Typescript error:
Type instantiation is excessively deep and possibly infinite
on seemingly benign types like this:
import {DescriptionSchema} from "project/other/package";
export const PlanStepSchema = z.object({
id: z
.string()
.describe("A unique identifier for the step (e.g., 'create_user_model')."),
description: DescriptionSchema
});
When the type itself isn't suspicious, I've found this is almost always due to a mismatched dependency between 2 packages in your repository. In this case "other/package" has a different version of the "zod" dependency, and some detail of the internals of the typing is causing things to explode.
(This has happened to me enough now that I wanted to highlight the version mismatch as opposed to the normal recursive type issues).
Aligning the package versions usually fixes the issue, either manually or by using a tool like ncu. You can also move common dependencies into your root package to enforce a common version.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With