I'm trying to ensure that the component passed to another component as a prop (i.e. <Foo Component={Bar} />) is declared with the correct props.
This works fine when the component being passed in has props defined. However, if there are no props defined, TypeScript doesn't throw an error.
Here's an example:
import { ComponentType } from 'react';
type A = {
foo: string;
}
type B = {
Component: ComponentType<A>;
}
const Test = ({ Component }: B) => (
<Component foo="test" />
);
const NoProps = () => <div />;
const CorrectProps = ({ foo }) => <div />;
const IncorrectProps = ({ bar }) => <div />;
// does not error - but it should?
const C = () => <Test Component={NoProps} />;
// no error as expected
const D = () => <Test Component={CorrectProps} />;
// errors as expected
const E = () => <Test Component={IncorrectProps} />;
I was wondering if it is possible to enforce the correct props to be defined?