title: Is there a way to constraint a generic type to plain objects only in typescript?
body: <p>Using typescript, is there a way to constraint a generic type to allow values of type object only? Not array and other types.</p>
  
  <p>For eg:</p>
  
  <pre class="lang-js prettyprint-override"><code>function check&lt;O extends object&gt;(ob: O): O {
    return ob
  }
  
  check({}) // should be fine
  check([]) // should show error, but does not.
  </code></pre>
  
  <p>A possible real world use case:</p>
  
  <pre class="lang-js prettyprint-override"><code>function extend&lt;A extends object, B extends object&gt;(a: A, b: B): A &amp; B {
    return {
      ...a,
      ...b,
    };
  }
  
  // This is fine, return type is { x: number } &amp; { y: string }
  extend({x: 5}, {y: "str"})
  
  // This should not be allowed
  // Return type is number[] &amp; string[]
  // Accessing a property yields impossible types like number &amp; string
  extend([1,2,3], ["s", "i", "d"])
  
  // More examples for variants which I don't want to allow
  extend({}, function() {})
  extend({}, new Map())
  </code></pre>