title: How to specify a different return type based on number of arguments passed to rest parameter function
body: <p>How do I create an arrow function with rest parameters that have different return types based on the number of passed arguments?</p>
  
  <p>E.g. I want a <code>safeId()</code> that has the following return types:</p>
  
  <pre><code>safeId() // () =&gt; string
  safeId('foo') // (obj: any) =&gt; string
  safeId('foo', 4, {}, ['hi']) // (...obj: any[]) =&gt; string[]
  
  // Currently my return type isn't specific:
  const safeId = (...objects: any[]) =&gt; string | string[] =&gt; {
    // Simplified
    if (objects.length &gt; 1) return sanitizedObjectIds(objects) // string[]
    return 'id'
  }
  </code></pre>