Skip to content

tsgo "Type instantiation is excessively deep and possibly infinite" error when using react-hook-form #988

Open
@justinsmid

Description

@justinsmid

My project makes heavy use of react-hook-form. A quick git grep tells me we have 310 forms.

On two of them we are getting the "Type instantiation is excessively deep and possibly infinite" error when using tsgo. We have never had this error in these places with tsc.
We don't do anything special on those two forms compared to our other forms as far as I can tell, but it does seem to be consistently on those and only those two forms.

The error occurs when rendering the FormProvider. This component expects the entire result of useForm, so you're expected to spread the whole form when using it, which I can imagine gets quite heavy during typechecking:
https://github.com/react-hook-form/react-hook-form/blob/90cdaee9ba148e6c28fe3cb69f885ae1541f7c04/src/types/form.ts#L916

// ...

const form = useForm({ ... })

return (
// v -- "Type instantiation is excessively deep and possibly infinite" error occurs here in tsgo
  <FormProvider {...form}>
    {/* ... */}
  </FormProvider
)

Unfortunately I have not been able to reproduce the issue in a standalone repository.
We also have a wrapper around their useForm to give us more accurate types, which makes fairly heavy use of generics, so I imagine that's contributing to the issue, but even with that wrapper I have not been able to reproduce it standalone.
I'm guessing it's partially related to the large amount of these forms I have in my actual repo.

I'm not sure if this is something you can work on or help me out with without a reproduction, but figured I'd try anyways.
Would be happy to provide more details on our usage if there's anything you think would be helpful, but our actual repo is private so unfortunately I cannot publicly share it fully.

(Using "@typescript/native-preview": "7.0.0-dev.20250529.1")

Metadata

Metadata

Assignees

No one assigned

    Labels

    Domain: Type CheckingRelated to type checking, grammar checking

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions