title: How to infer return type of a property function as the type of a property?
body: <p>Is there a way in typescript to get the return type of a object property function and use that as the type of another object property function's parameter?</p>
  <p>For example:</p>
  <pre><code>const request = {
    
    // Infer the return type of this data function as shown to below...
    data: () =&gt; ({ people: [&quot;bob&quot;, &quot;jack&quot;] }),
  
    // The type of `data` parameter should now be an object with people as a prop with the type of string[].
    run: (data) =&gt; Promise.resolve(data.people),
    
  }
  </code></pre>
  <p>I'm not even sure if this is possible, but the closest I've got is the following...</p>
  <pre><code>interface IRequest&lt;TDataProps = {}&gt; {
    data: () =&gt; TDataProps,
    run: &lt;TReturnRun&gt;(data: TDataProps) =&gt; MaybePromise&lt;TReturnRun&gt;;
  }
  
  // So can manually provide the type but not inferred...
  const request: IRequest&lt;{ people: string[] }&gt; = {
    data: () =&gt; ({ people: [&quot;bob&quot;, &quot;jack&quot;] }),
    run: (data) =&gt; Promise.resolve(data.people),
  }
  </code></pre>
  <p>Many thanks</p>