title: TypeScript Interface Function Property: What's the difference?
body: <p>Can someone please explain, why in this code the assignment to the constant of type InterfaceA works, but the assignment to the constant of type InterfaceB throws an error:</p>
  
  <pre><code>interface InterfaceA {
    doSomething (data: object): boolean;
  }
  
  interface InterfaceB {
    doSomething: (data: object) =&gt; boolean;
  }
  
  function doIt (data: { type: string; }): boolean {
      return true;
  }
  
  const A: InterfaceA = {
      doSomething: doIt
  };
  const B: InterfaceB = {
      doSomething: doIt
  };
  
  </code></pre>
  
  <p>For an online demo, see:
  <a href="http://www.typescriptlang.org/play/index.html?ssl=19&amp;ssc=1&amp;pln=1&amp;pc=1#code/JYOwLgpgTgZghgYwgAgJLmvJBBZBvAWAChlkATAewGUKBbCMAC1AHNkAKMuMOALmQoAjAFYQEYAJT9BFCgBsIcEAG5iAX2LFQkWIhTodWCACF8xUpRr0mrfp258BIsZOQBeAHzIZ8xSvWaRDAAriDiwBQg5BSoYBxcPPx4yGAAngAOEPwAzmBQrMrIalLesgpKZkQAkFAMwVBRecEQqkQaRMQIkbnI2PwGmHq4bpVVlnQMzCAs-JSx6q1dID3G-Ri6SKYjhNXj1lMz0fNtrUA" rel="noreferrer">http://www.typescriptlang.org/play/index.html?ssl=19&amp;ssc=1&amp;pln=1&amp;pc=1#code/JYOwLgpgTgZghgYwgAgJLmvJBBZBvAWAChlkATAewGUKBbCMAC1AHNkAKMuMOALmQoAjAFYQEYAJT9BFCgBsIcEAG5iAX2LFQkWIhTodWCACF8xUpRr0mrfp258BIsZOQBeAHzIZ8xSvWaRDAAriDiwBQg5BSoYBxcPPx4yGAAngAOEPwAzmBQrMrIalLesgpKZkQAkFAMwVBRecEQqkQaRMQIkbnI2PwGmHq4bpVVlnQMzCAs-JSx6q1dID3G-Ri6SKYjhNXj1lMz0fNtrUA</a></p>
  
  <p>To me, both interfaces are defining the same, only the notation is different.</p>
  
  <p>If this is not a bug in TypeScript, and there is a real reason, then let's come to my second question:
  I need to specify, that "doSomething" is optional and can either be a function, or a RegExp:</p>
  
  <pre><code>interface InterfaceB {
    doSomething?: ((data: object) =&gt; boolean) | RegExp;
  }`
  </code></pre>
  
  <p>How could I achieve this, with the notation of InterfaceA?</p>