title: Array reduce and optional values in typescript
body: <p>Say I have the following foldable interface:</p>
  
  <pre><code>export interface Foldable&lt;F&gt; {
    reduce: &lt;A&gt;(fn: (b: A, a: A) =&gt; A, initial: A, foldable: F) =&gt; A;
  }
  </code></pre>
  
  <p>And then I want to implement it for array:</p>
  
  <pre><code>export const getArrayFold = &lt;A&gt;(): Foldable&lt;Array&lt;A&gt;&gt; =&gt; {
    return {
      reduce: (fn, initial, array) =&gt; {
        return array.reduce(fn, initial);
      }
    };
  };
  </code></pre>
  
  <p>But the compiler complains with:</p>
  
  <blockquote>
    <p>Argument of type '(b: A, a: A) => A' is not assignable to parameter of
    type '(previousValue: A, currentValue: A, currentIndex: number, array:
    A[]) => A'.   Types of parameters 'a' and 'currentValue' are
    incompatible.
        Type 'A' is not assignable to type 'A'. Two different types with this name exist, but they are unrelated.</p>
  </blockquote>
  
  <p>I don't understand how there are two different types of <code>A</code> here.</p>