title: How to fold two different types? FP-TS
body: <p>I'm learning FP with FP-TS and I just hit a road block:</p>
  <p>I have the following function in my repository:</p>
  <pre class="lang-js prettyprint-override"><code>// this is the repository
  export const findBook = (id: string) =&gt; TaskEither&lt;Error, Option&lt;ParsedBook&gt;&gt; 
  </code></pre>
  <p>that part is easy and makes sense to me. The issue is when I try to call it from my controller:</p>
  <pre class="lang-js prettyprint-override"><code>// this is the controller
  export const getBook = (req: unknown) =&gt; Task&lt;string | ParsedBook&gt;
  </code></pre>
  <p>Anyways, here's my <code>getBook</code> and what I'm trying to do:</p>
  <pre class="lang-js prettyprint-override"><code>const getBook: (req: unknown) =&gt; T.Task&lt;string | ParsedBook&gt; = flow(
    getBookByIdRequestV.decode, // returns Either&lt;Errors, GetBookByIdRequest&gt;
    E.fold(
      () =&gt; T.of('Bad request!'),
      flow(
        prop('params'),
        prop('id'),
        findBook, // returns TaskEither&lt;Error, Option&lt;ParsedBook&gt;&gt;
        TE.fold(
          () =&gt; T.of('Internal error.'),
          O.fold(
            () =&gt; T.of('Book not found.'),
            (book) =&gt; T.of(book) // this line results in an error
          )
        )
      )
    )
  )
  </code></pre>
  <p>The issue is that the above code gives me an error:</p>
  <pre><code>Type 'ParsedBook' is not assignable to type 'string'
  </code></pre>
  <p>I think the issue is that <code>E.fold</code> expects the result of <code>onLeft</code> and <code>onRight</code> to return the same type:</p>
  <pre class="lang-js prettyprint-override"><code>fold&lt;E, A, B&gt;(onLeft: (e: E) =&gt; B, onRight: (a: A) =&gt; B): (ma: Either&lt;E, A&gt;) =&gt; B
  </code></pre>
  <p>However, it might not only return a <code>Task&lt;string&gt;</code>, but a <code>Task&lt;ParsedBook&gt;</code> as well.</p>
  <p>I tried using <code>foldW</code>, which widens the type, but same error as well.</p>
  <p>I don't really know what to do; I feel like the way I am modelling the types in my code are bad?</p>
  <p>Here's the Codesandbox if it helps: <a href="https://codesandbox.io/s/tender-chandrasekhar-5p2xm?file=/src/index.ts" rel="nofollow noreferrer">https://codesandbox.io/s/tender-chandrasekhar-5p2xm?file=/src/index.ts</a></p>
  <p>Thank you!</p>