I want to define a parent element where I need to pass down some react elements as props. I want to add some requirements on the props to the child components but I can't get my typescript working exactly as intended. Here is a minimal example
import * as React from "react";
function JSXElementChild() {
return <div>Child One</div>;
}
const ReactFCChild: React.FC<{ label: string }> = ({ label }) => {
return <div>{label}</div>;
};
function Parent({
children
}: {
children: React.ReactElement<{ label: string }>[];
}) {
return (
<div>
{children.map((child) => (
<div key={child.props.label}>{child}</div>
))}
</div>
);
}
export default function App() {
return <Parent children={[<JSXElementChild />, <ReactFCChild />]} />;
}
Parent component requires children as props and these children requires a label: string as props. Now the above does correct mark a typescript issue with ReactFCChild; Property 'label' is missing in type '{}' but required in type '{ label: string; }'.ts(2741). However JSXElementChild does not yield any issues. How to fix that?