Skip to content

Recursive type: Type instantiation is excessively deep and possibly infinite.  #577

@JorikSchellekens

Description

@JorikSchellekens

I'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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions