type ChildProps = { vegetables: string[] } function MyComponent({ children }: { children: React.ReactElement<ChildProps> }) { React.Children.forEach(children, (child) => { console.log(child.props.vegetables) // no error! console.log(child.props.fruit) // error! Property 'fruit' does not exist on type 'ChildProps' }) }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter