title: typescript: validate function argument based on callback return type
body: <p>I'm trying to type a function witch run a callback for each array item and extend that item with a new properties:</p>
  <pre class="lang-js prettyprint-override"><code>interface Row {
      a: number
  }
  export function extender&lt;
    Data extends Row[],
    T extends object,
    Props extends keyof T
    &gt;(data: Data, extend: (row: Row) =&gt; T, newProp?: Props): (T &amp; Row)[] {
        return data.map(row =&gt; ({
            ...row,
            ...extend(row)
        }))
  }
  </code></pre>
  <p>This draft seems to be working when I call</p>
  <pre class="lang-js prettyprint-override"><code>extender([{ a: 1 }, { a: 2 }], () =&gt; ({ once: 1, more: 2 }), 'once')
  </code></pre>
  <p>But once I trying to use <code>row</code> argument in <code>extend</code> callback, I get an error <code>Argument of type '&quot;once&quot;' is not assignable to parameter of type 'undefined'.</code>:</p>
  <pre class="lang-js prettyprint-override"><code>// TS_ERROR: Argument of type '&quot;once&quot;' is not assignable to parameter of type 'undefined'.
  extender([{ a: 1 }, { a: 2 }], (row) =&gt; ({ once: 1, more: row.a * 2 }), 'once')
  </code></pre>
  <p>What am I missed?</p>