How to hang properties on built-in objects in Tyepscript?

problem description

when traversing ReactChildren with React.Children.forEach, you need to determine the type of child based on the attribute you hang, but writing child.type directly will cause an error: the attribute "type" does not exist on the
[ts] type "ReactChild".
clipboard.png

tried to define interface, but to no avail.

interface ReactChild{
  type: string;
}

seek the answer of the Great God

Oct.11,2021

first of all, the parameter is an attribute that can be defined

...forEach((child: ReactChild) => {  
     
})

then you can also define the attribute type directly

(child as ReactChild).type
Menu