title: Infer an argument's type to avoid a generic?
body: <p>How can I infer <code>O</code> from the specific <code>obj</code> passed as the parameter?</p>
  
  <pre><code>export function pubsubs&lt;O extends {[key: string]: Pubsub}&gt;(
    obj: O // extends infer U ? U : never
     //        ↑
     //    (failed attempt to infer)
  ): {
    pub: Pubify&lt;O&gt;
    sub: Subify&lt;O&gt;
  } {
  
    // ... generate pub and sub based on obj ...
  
    return {pub, sub}
  }
  </code></pre>
  
  <p>Desired result:</p>
  
  <pre><code>const {pub, sub} = pubsubs({ // ← (want to infer from this first arg)
   //                      ↑
   //             (no generic)
  
    userLogout: pubsub(),
    userLoading: pubsub(),
    userError: pubsub&lt;(error: Error) =&gt; void&gt;(),
    userLogin: pubsub&lt;(auth: LoginDetail) =&gt; void&gt;(),
  })
  
  // but the typings fail to be inferred!
  sub.userError(error =&gt; {})
   //            ↑
   //    (error type is 'any' )
  </code></pre>
  
  <p>Workaround without inference:</p>
  
  <pre><code>const input = {
    userLogout: pubsub(),
    userLoading: pubsub(),
    userError: pubsub&lt;(error: Error) =&gt; void&gt;(),
    userLogin: pubsub&lt;(auth: LoginDetail) =&gt; void&gt;(),
  }
  
  const {pub, sub} = pubsubs&lt;typeof input&gt;(input)
   //                         ↑
   //        (should be inferred)
  
  // typings are preserved
  sub.userError(error =&gt; {})
   //            ↑
   //       (typescript knows)
  </code></pre>
  
  <p>How can I infer the type and avoid the generic type parameter?</p>