We have some complex compositions of components, and I'm having trouble making them typesafe. Based on the code below, I'd have expected Typescript to be able to provide types for Menu.Item or Menu.Link, but it doesn't for some reason, they're inferred as "any" (which is refined to JSX.Element<any> when you wrap it in JSX. Any idea why this is happening?
import * as React from 'react';
type RootFunctionComponent<OwnProps, SubComponents> = React.FunctionComponent<OwnProps> & SubComponents;
interface ItemProps {
text: string;
};
interface LinkProps {
href: string;
}
const Item: React.FunctionComponent<ItemProps> = props => <div {...props} />;
const Link: React.FunctionComponent<LinkProps> = props => <div {...props} />;
interface MenuSubComponents {
Item: React.FunctionComponent<;
Link: typeof Link;
}
const Menu: React.FunctionComponent<{}, MenuSubComponents> & MenuSubComponents = props => <div {...props} />
Menu.Item = Item;
Menu.Link = Link;
const Test: React.FunctionComponent<{}> = () => {
return <>
<Menu>
<Menu.Item text={false} />
<Menu.Link />
</Menu>
</>
}
Result:
