Discriminated Union of Generic type : <p>I'd like to be able to use <a href="https://basarat.gitbooks.io/typescript/docs/types/discriminated-unions.html" rel="noreferrer">union discrimination</a> with a generic.  However, it doesn't seem to be working:</p>

<p>Example Code (<a href="http://www.typescriptlang.org/play/#src=interface%20Foo%7B%0D%0A%20%20%20%20type%3A%20&#39;foo&#39;%3B%0D%0A%20%20%20%20fooProp%3A%20string%0D%0A%7D%0D%0A%0D%0Ainterface%20Bar%7B%0D%0A%20%20%20%20type%3A%20&#39;bar&#39;%0D%0A%20%20%20%20barProp%3A%20number%0D%0A%7D%0D%0A%0D%0Ainterface%20GenericThing%3CT%3E%20%7B%0D%0A%20%20%20%20item%3A%20T%3B%0D%0A%7D%0D%0A%0D%0A%0D%0Alet%20func%20%3D%20(genericThing%3A%20GenericThing%3CFoo%20%7C%20Bar%3E)%20%3D%3E%20%7B%0D%0A%20%20%20%20if%20(genericThing.item.type%20%3D%3D%3D%20&#39;foo&#39;)%20%7B%0D%0A%0D%0A%20%20%20%20%20%20%20%20genericThing.item.fooProp%3B%20%2F%2F%20this%20works%2C%20but%20type%20of%20genericThing%20is%20still%20GenericThing%3CFoo%20%7C%20Bar%3E%0D%0A%0D%0A%20%20%20%20%20%20%20%20let%20fooThing%20%3D%20genericThing%3B%0D%0A%20%20%20%20%20%20%20%20fooThing.item.fooProp%3B%20%2F%2Ferror!%0D%0A%20%20%20%20%7D%0D%0A%7D%0D%0A" rel="noreferrer">view on typescript playground)</a>:</p>

<pre><code>interface Foo{
    type: 'foo';
    fooProp: string
}

interface Bar{
    type: 'bar'
    barProp: number
}

interface GenericThing&lt;T&gt; {
    item: T;
}


let func = (genericThing: GenericThing&lt;Foo | Bar&gt;) =&gt; {
    if (genericThing.item.type === 'foo') {

        genericThing.item.fooProp; // this works, but type of genericThing is still GenericThing&lt;Foo | Bar&gt;

        let fooThing = genericThing;
        fooThing.item.fooProp; //error!
    }
}
</code></pre>

<p>I was hoping that typescript would recognize that since I discriminated on the generic <code>item</code> property, that <code>genericThing</code> must be <code>GenericThing&lt;Foo&gt;</code>.  </p>

<p>I'm guess this just isn't supported?  </p>

<p>Also, kinda weird that after straight assignment, it <code>fooThing.item</code> loses it's discrimination.</p>
