title: How to return different types based on parameters in a React.useCallback
body: <p>I want to return an object when I have a certain prop in the parameter of my function, and a <code>string</code> when not.</p>
  <p>I can't use functions overloads because it is used in a type that is shared with React components, in React.useCallback.</p>
  <p>I tried:</p>
  <pre><code>type FileType = {
      name: string
      content: string
  }
  
  // This is a type that I use in many part of my code. I would like the result of onSave to depend on the props it receive
  type Props = {
      onSave: &lt;T extends FileType | undefined&gt;(data: {
          id: string
          file: T
      }) =&gt; T extends FileType ? FileType : string
  }
  
  const isFile = (o: unknown): o is FileType =&gt; {
      return o !== undefined
  }
  
  
  // Here you can read the error
  const insert: Props['onSave'] = prop =&gt; isFile(prop.file) ? prop.file : prop.id)
  
  // Here is how the function is written in my code. But React doesn't exist in this playground
  // const insert = React.useCallback&lt;Props['onSave']&gt;(prop =&gt; isFile(prop.file) ? prop.file : prop.id, [])
  
  </code></pre>
  <p>the error:</p>
  <pre><code>Type 'string | (T &amp; FileType)' is not assignable to type 'T extends FileType ? FileType : string'.
    Type 'string' is not assignable to type 'T extends FileType ? FileType : string'.
  </code></pre>
  <p><strong>Playground Link:</strong> <a href="https://www.typescriptlang.org/play?#code/C4TwDgpgBAYglgGwgFXNAvFA3gKCvqAOwEMBbCALigGdgAnOQgczwIGMB7Q4Cbq2hsxwBfHDgD04qMgAWcalHlRiUUJFUziwKAEkoAV2rRGUUsUIgoYYnW0cAZqcucAJhAB0uqAHcO+hC5QCHAA1tDAMtB0ENT+do5cAMrEAG7hHFBukISBXBrQYHQcYApw2tFsEHBpOGrQAApFJVCYuARQSamUUAA8yFAQAB48OQrwSKjqAD4GORD2jBAuAHwAFC5axFRt7QRwLvz0jCy7BAtIVMis+MIAlC3L0gPDvC5jiChoUAD8sB+T0EOghYohwnEItEU1HGGCgqw4VH0hBChA43kItyoGSUMIBD2w1yg0WA+johA6UAAhOhMEi3AtCEsRGIJFIABIQaJQEB+KBscxEiDEQIRaCcop0MFcSGMIy2KiNYrUADaAHJOmlVQBdFpWJr4+Qw1aFYruc4Qe6-E1gM0fKBUa3ufa3MSSKAcrlKGRo-JQexItjAOB5JTeBjAEaKcmkZwcNyeABC+m0ACUhYHMhwYoRVdohvJtCYIkowAhiCAmEU6ay+dLCxDOdpMGniIH3IYIABhYgIBAAI1bIR6ipKao1EG1a2tBuhH2NTVtSEtetN5vtK5t+wANFBlVqXUA" rel="nofollow noreferrer">Provided</a></p>