title: Restrict generic type T to not being undefined in TypeScript?
body: <p>I defined the <code>get(o, key)</code> function that should work with any Object that satisfy the <code>{ get: (key: K) =&gt; R }</code> interface.</p>
  <p>Additionally I would want to restrict the result <code>R</code> to not being <code>undefined</code>. Is that possible?</p>
  <p>How to to change the example below so that it won't compile, because of method <code>Params::get(key: string): number | undefined</code> that returns <code>undefined</code>?</p>
  <pre><code>function get&lt;K, R&gt;(o: { get: (key: K) =&gt; R }, key: K): R {
    return o.get(key);
  }
  
  class Params {
    constructor(public values: { [key: string]: number }) { }
  
    get(key: string): number | undefined {
      return this.values[key]
    }
  }
  const params = new Params({ a: 10 });
  
  console.log(get(params, &quot;a&quot;))
  </code></pre>