Given a react component that is generic on two properties, a load function returning type T, and the children (which is a single function taking a parameter of type T)...
class Test<T> extends React.Component<{
load: () => T;
children: (r: T) => JSX.Element;
}> {
render() {
return this.props.children(this.props.load());
}
}
typescript is not able to infer the type of res from the return value of load, it defaults to type {}.
<Test load={() => ({ test: 'x' })}>
{res =>
<span>
{res.test}
</span>}
</Test>;
Is this a bug, or is typescript not able to infer based on return values -- as it looks like typing of JSX children is supported.
EDIT:
for background, the usecase is creating a "lazy" component which accepts load function which return a promise resolving to some further JSX.