Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Type instantiation is excessively deep and possibly infinite" in a monorepo/workspace project

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
});
like image 404
rjpower Avatar asked Nov 01 '25 16:11

rjpower


1 Answers

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.

like image 135
rjpower Avatar answered Nov 04 '25 09:11

rjpower



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!