Skip to content

[utils] An object type that contains Json causes a recursive error in conjunction with Draft/WritableDraft types from Immer #10205

Description

@mcmire

If you have an object type such as:

{
  foo: Json
}

and you use it to change state within an Immer produce callback — such the callback that update in BaseController v2 takes — then you will get an error:

Type instantiation is excessively deep and possibly infinite

This is happening because Json is a recursive type and Draft and WritableDraft trampoline as they recurse through that Json type. There's an open bug report on the Immer issue tracker with a proposed fix that was eventually reverted.

We should work out some way to avoid this.

Activity

  1. MajorLift commented on Jan 24, 2024

    @MajorLift
    Contributor

    Some starting points for tackling the "Type instantiation is excessively deep" error:

    This might not be enough to resolve the issue if the mutual recursion depth is infinite even with tail call elimination.

  2. MajorLift commented on Feb 23, 2024

    @MajorLift
    Contributor

    Might be resolved by TypeScript 5.5: microsoft/TypeScript#57293

  3. mcmire commented on Oct 28, 2024

    @mcmire
    CollaboratorAuthor

    I checked the Immer repo and it looks like this problem still exists: immerjs/immer#839

  4. changed the title [-]An object type that contains `Json` causes a recursive error in conjunction with `Draft`/`WritableDraft` types from Immer[/-] [+][utils] An object type that contains `Json` causes a recursive error in conjunction with `Draft`/`WritableDraft` types from Immer[/+] on Sep 11, 2026
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