Skip to content

TS5115 in published Zod 4.5–4.6 types after #64372Β #64605

Description

πŸ”Ž Search Terms

TS5115, "appear infinitely circular", base type arguments, zod, 64372

πŸ•— Version & Regression Information

⏯ Playground Link

No response

πŸ’» Code

interface Internals<I = unknown> { input: I }
interface Schema { _zod: Internals }
type RecordInput<V extends Schema> = V extends unknown ? Record<string, V["_zod"]["input"]> : never;
interface RecordSchema<V extends Schema> extends Schema { _zod: Internals<RecordInput<V>> }
interface UnionInternals<T extends readonly Schema[]> extends Internals<T[number]["_zod"]["input"]> {}
interface UnionSchema<T extends readonly Schema[]> extends Schema { _zod: UnionInternals<T> }
type JsonValue = { [k: string]: JsonValue };
type _Json = UnionSchema<[RecordSchema<Json>]>;
type _JsonInternals = _Json["_zod"];
interface JsonInternals extends _JsonInternals { input: JsonValue }
interface Json extends _Json { _zod: JsonInternals }

With the published package (zod@4.6.5, skipLibCheck: true):

import * as z from "zod";
export const A = z.array(z.json()); // TS5115

πŸ™ Actual behavior

TS5115 "Instantiations of the following types appear infinitely circular" on RecordSchema<Json>. The same shape is Zod's z.json() type, so Zod 4.5.0 through 4.6.5 fail on 7.1:

  • with skipLibCheck: false, every project that imports Zod gets TS5115 from Zod's own declarations
  • with skipLibCheck: true, z.array(z.json()), z.record(z.string(), z.json()) or .parse() on an object holding z.json() reports it in user code, and the record's input type becomes Record<string, any>

πŸ™‚ Expected behavior

No error, as in 7.0.2.

Additional information about the issue

Those versions get about 62M of Zod's 365M weekly npm downloads. The member-declaration fix from #64372 (comment) is merged in colinhacks/zod#6645 and goes out in the next Zod release, but projects that stay on 4.5.0–4.6.5 will still break when they move to 7.1.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions