TypeScript reports non-existent properties in generic function
<p>Consider the following generic function in TypeScript:</p>

<pre><code>interface Foo { id: string; }
const foo = &lt;Foo&gt;{id: 'bar'};
function baz&lt;T&gt;(x: T) { console.log(x.id); }
baz(foo);
</code></pre>

<p>This doesn't compile:</p>

<blockquote>
  <p><code>test.ts(6,17): error TS2339: Property 'id' does not exist on type 'T'.</code></p>
</blockquote>

<p>It seems to me that TypeScript ought to be able to deal with this situation. If it can't, then I have to do something like this:</p>

<pre><code>interface IHasId { id: string; }
interface Foo extends IHasId { }
const foo = &lt;Foo&gt;{id: 'bar'};
function baz&lt;T&gt;(x: IHasId) { console.log(x.id); }
baz&lt;Foo&gt;(foo);
</code></pre>

<p>Is there any alternative or more idiomatic way to deal with this situation?</p>