TS5115 "infinitely circular" on `.catchall(z.json())` with the TypeScript 7.1 nightlies
the typescript 7.1 nightlies (7.1.0-dev.20260929.1 and later) report this on any .catchall(z.json()):
import { z } from 'zod'
export const schema = z.object({ n: z.number() }).catchall(z.json())error TS5115: Instantiations of the following types appear infinitely circular: 'IsOptionalIn', '$ZodTypeInternals', '$InferZodRecordInput'.same with zod 4.5.4 and 4.6.5. typescript 7.0.2 is fine
it comes from this typescript change, which makes the checker stricter about a type that references itself through the type arguments of its base type:
zod showed up in their top 1000 repo run for it, and anders suggested taking the type arguments off the $ZodTypeInternals base of $ZodRecordInternals and declaring input/output directly:
export interface $ZodRecordInternals<Key extends $ZodRecordKey = $ZodRecordKey, Value extends SomeType = $ZodType> extends $ZodTypeInternals {
def: $ZodRecordDef<Key, Value>;
isst: errors.$ZodIssueInvalidType | errors.$ZodIssueInvalidKey<Record<PropertyKey, unknown>>;
optin?: "optional" | undefined;
optout?: "optional" | undefined;
output: $InferZodRecordOutput<Key, Value>;
input: $InferZodRecordInput<Key, Value>;
}(his comment has input: $InferZodRecordOutput, i think thats a typo since input should stay $InferZodRecordInput)
i tried that in 4.6.5's v4/core/schemas.d.ts and .d.cts. the repro is clean on both the nightly and 7.0.2, and z.input/z.output of a z.record(...) come out the same as before. PRs look limited to collaborators here so i couldn't open one, but the change plus a type test is on this branch if it's useful:
Source: colinhacks/zod