Generic classes, constraints and inheritance
<p>So I'm fairly new to Typescript, and also generics. I'm not sure if I found a bug/limitation of Typescript or I'm missing the correct pattern to do what I want.</p>

<p>I have a <code>Widget</code> generic base class that holds a value of type <code>T</code>. For example it could be <code>string</code>, <code>number</code>, whatever.</p>

<p>I want to have a <code>Widget</code> subclass that will hold an <code>Array&lt;T&gt;</code> as its value, eg <code>string[]</code>, <code>Date[]</code> etc. </p>

<p>Example consumer code:</p>

<pre><code>let w = new Widget&lt;string&gt;();
w.value = "abc";

let aw = new ArrayWidget&lt;number[]&gt;();
aw.value = [1, 2, 3];
</code></pre>

<p>The closest I have come is this:</p>



<pre class="lang-js prettyprint-override"><code>class Widget&lt;T&gt; {
    public value:T;
}

class ArrayWidget&lt;U extends T[], T&gt; extends Widget&lt;U&gt; {
    setValue() {
        let v = new Array&lt;T&gt;();
        this.value = v; // error: Type 'T[]' is not assignable to type 'U'

    }
}

let aw = new ArrayWidget&lt;string[], string&gt;();
aw.value = ["a", "b", "c"];
</code></pre>

<p>How can I specify that <code>ArrayWidget</code>'s generic class is actually an array of <code>&lt;T&gt;</code>? Currently I have to explicitly cast like so:</p>

<pre class="lang-js prettyprint-override"><code>this.value = v as U;
</code></pre>

<p>And everything is happy (the consuming code works as expected). Thanks!</p>