title: Typescript function generic can infer type automatically, is there an equivalent for object generic type?
body: <pre><code>function &lt;Obj extends object&gt;funName(o:Obj): Obj{
    ...
  }
  </code></pre>
  <p>Function generic as above enforces a certain relationship between params and return types, without forcing the user to actually pass a type.</p>
  <p>Is there an equivelant object generic type (POJO - plain old JS object), without forcing the user to pass a type?</p>
  <pre><code>type Props = &lt;S extends string&gt;{
    selectedTab: S 
    tabs: Record&lt;S, any&gt;
  }
  
  const props1: Props = { //ok 
    selectedTab: &quot;about&quot;
    tabs: {
      about: {...} 
    }
  }
  
  const props2: Props = { //Error
    selectedTab: &quot;contact us&quot;
    tabs: {
      about: {...} 
    }
  }
  </code></pre>
  <p>I know this could be achieved by passing a type.</p>
  <pre><code>const props1: Props&lt;&quot;about&quot;&gt; = { 
    ...
  }
  </code></pre>
  <p>But since automatic inference is possible for functions, perhaps it can also be used for objects.</p>