You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You have to assert the child type within the component, rather than relying on the props.
Something like this should work:
// your lower componenttypeAllowedChildComponentProps={ ... }constAllowedChildComponent=[...];// the high level componenttypeYourComponentProps={children?: React.ReactElement<AllowedChildComponentProps>|React.ReactElement<AllowedChildComponentProps>[]}constYourComponent=(props: YourComponentProps)=>{return({children &&React.Children.map(children,child=>{if((childasReactElement).type===AllowedChildComponent){// go ahead}else{// throw or something}});}
microsoft/TypeScript#13618
Example: We create High-level component package with strong typed how the lower components designed to be.
The text was updated successfully, but these errors were encountered: