title: Typescript: type inference for children on generic react component
body: <p>Given a react component that is generic on two properties, a <code>load</code> function returning type <code>T</code>, and the children (which is a single function taking a parameter of type <code>T</code>)...</p>
  
  <pre><code>class Test&lt;T&gt; extends React.Component&lt;{
    load: () =&gt; T;
    children: (r: T) =&gt; JSX.Element;
  }&gt; {
    render() {
      return this.props.children(this.props.load());
    }
  }
  </code></pre>
  
  <p>typescript is not able to infer the type of <code>res</code> from the return value of <code>load</code>, it defaults to type <code>{}</code>.</p>
  
  <pre><code>&lt;Test load={() =&gt; ({ test: 'x' })}&gt;
    {res =&gt;
      &lt;span&gt;
        {res.test}
      &lt;/span&gt;}
  &lt;/Test&gt;;
  </code></pre>
  
  <p>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.</p>
  
  <p>EDIT: </p>
  
  <p>for background, the usecase is creating a "lazy" component which accepts <code>load</code> function which return a promise resolving to some further JSX.</p>