React-Hook-Form: Trying to use recursion in class model in React.js (TS)

Viewed 147

I'm trying to define a class model that contains itself in react:

  class CategoryModel {
    id: number;
    name: string;
    parentCategory: CategoryModel;
  }

This code works fine. however, when i try to build a form to add a new category i get an error in the register object:


Type of properType of property 'parentCategory' circularly references itself in mapped type '{ [K in keyof CategoryModel]-?: PathImpl<K & string, CategoryModel[K]>; }'.  TS2615

    29 |
    30 |                 <TextField
  > 31 |                     {...register("name")}
       |                         ^
    32 |                     label="name"
    33 |                     variant="standard"
    34 |                     type="text"

The error isn't part of the name; when i removed it the error simply appear on another part of the form. The problem disappear when i deleted the line "parentCategory: CategoryModel;".

thanks for any help!

0 Answers
Related