title: Inference in generic function parameters
body: <p>Basic type inference is very straightforward in TypeScript:</p>
  
  <pre><code>const bar = foo(); // bar: &lt;type that foo returns&gt;
  </code></pre>
  
  <p>Considering that generic parameter default value is <code>{}</code>, it would be reasonable to expect that the code below will cause type error, because callback function returns <code>number</code> and not <code>{}</code>:</p>
  
  <pre><code>function foo&lt;T = {}&gt;(callback: () =&gt; T): T {
      return callback();
  }
  
  let bar = foo(() =&gt; 1); // bar: number
  </code></pre>
  
  <p>But it's known that <code>T</code> is inferred from callback return value, it is:</p>
  
  <pre><code>function foo&lt;number&gt;(callback: () =&gt; number): number
  </code></pre>
  
  <p>How exactly does this happen and where is this behaviour prescribed? A quote from documentation or explanations from TypeScript developers that shed some light would be appreciated.</p>
  
  <p>Is it possible to force <code>T</code> to be default value (<code>{}</code> or whatever specified in <code>&lt;T = ...&gt;</code>) and not be inferred in <code>foo(() =&gt; 1)</code> call? This may be desirable behaviour in some cases.</p>
  
  <p>If there other counter-intuitive cases of inference in TypeScript, their mention is welcome too.</p>