title: Typescript - Generic implementation
body: <p>I could define an interface for object equality like:</p>
  
  <pre><code>interface IEquatable&lt;T&gt; {
      readonly equals: (x: T, y: T) =&gt; boolean
  }
  
  const stringEquatable: IEquatable&lt;string&gt; = {
      equals: (x: string, y: string) =&gt; x === y,
  }
  
  const numberEquatable: IEquatable&lt;number&gt; = {
      equals: (x: number, y: number) =&gt; x === y,
  }
  
  stringEquatable.equals("hello", "world") // false
  stringEquatable.equals("hello", "hello") // true
  
  numberEquatable.equals(1, 2) // false
  numberEquatable.equals(1, 1) // true
  </code></pre>
  
  <p>But I could also shortcut the implementation of <code>stringEquatable</code> and <code>numberEquatable</code> like:</p>
  
  <pre><code>interface IEquatable&lt;T&gt; {
      readonly equals: (x: T, y: T) =&gt; boolean
  }
  
  const strictEquatable = {
      equals: &lt;T&gt;(x: T, y: T) =&gt; x === y,
  }
  
  const stringEquatable: IEquatable&lt;string&gt; = strictEquatable
  const numberEquatable: IEquatable&lt;number&gt; = strictEquatable
  
  stringEquatable.equals("hello", "world") // false
  stringEquatable.equals("hello", "hello") // true
  
  numberEquatable.equals(1, 2) // false
  numberEquatable.equals(1, 1) // true
  </code></pre>
  
  <p>Coming from a csharp background, I'm confused as to what the following line is doing</p>
  
  <pre><code>const stringEquatable: IEquatable&lt;string&gt; = strictEquatable
  </code></pre>
  
  <p>I expected that implementing <code>IEquatable&lt;string&gt;</code> would require an implemenation of <code>equals</code> that closes over the <code>string</code> type, however <code>strictEquatable</code> has a generic implementation.</p>
  
  <p>What typescript feature is making this possible?</p>