title: How to infer return type based on return type of function in parameters
body: <p>I have the following function in my app:</p>
  <pre><code>const store = createStore(
    { value: false },
    (set, get) =&gt; ({
       changeValue: (newValue: boolean) =&gt; {
         set((state) =&gt; { state.value = newValue })
       }
    })
  )
  </code></pre>
  <p>I'm trying to get it so the type of the resulting <code>store</code> is:</p>
  <pre><code>{ value: boolean, changeValue: (newValue: boolean) =&gt; void }
  </code></pre>
  <p>without having to manually add the types. I feel like There should be a way to infer the types from the args of <code>createStore</code> within that function but I can't figure it out.</p>
  <p>Here is what my <code>createStore</code> currently looks like:</p>
  <pre><code>export const createStore = &lt;Document extends Record&lt;string, unknown&gt;&gt;(
    document: Document,
    actions: () =&gt; Record&lt;string, unknown&gt;,
  ) =&gt; {
    return Object.assign({}, document, actions())
  }
  
  const test = createStuff({ hello: 'world' }, () =&gt; ({ update: () =&gt; 'test' }))
  
  </code></pre>
  <p>In this case the type of <code>test</code> is</p>
  <pre><code>{
      hello: string;
  } &amp; Record&lt;string, unknown&gt;
  </code></pre>
  <p>and I would like it to be:</p>
  <pre><code>{
      hello: string;
  } &amp; { update: () =&gt; string }
  </code></pre>