title: Typescript generic constrain
body: <p>I am trying to write a generic getter function, given a key which should only return the type string|boolean|number. The default value should therefore be of the same type as the returned value</p>
  
  <p>Here is what I have tried.</p>
  
  <pre><code>getSomething = async&lt;T extends string | boolean | number&gt;
      (key: string, defaultValue: T): Promise&lt;T&gt; =&gt; {
        const foo = bar.getValue("foo"); // return type is undefined|string|boolean|number
        return foo === undefined ? defaultValue : foo;
   }
  </code></pre>
  
  <p>I get this error, not sure what is wrong.</p>
  
  <pre><code>Type 'string | number | boolean | T' is not assignable to type 'T'.
    'string | number | boolean | T' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'string | number | boolean'.
      Type 'string' is not assignable to type 'T'.
        'string' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'string | number | boolean'.ts(2322)
  </code></pre>
  
  <p>What could possibly be a subtype of 'string | number | boolean' is what puzzled me. Aren't they already a primitive type?</p>