DEV Community

Discussion on: Practical Guide to Fp-ts: P3 — Task, Either, TaskEither

Collapse
 
ryanleecode profile image
Ryan Lee • Edited

Task is just a promise, so you can just await it and use an if statement.

import * as T from 'fp-ts/lib/Task'

type Resp = { code: number; description: string }

declare const task: T.Task<Error | Resp>
(async() => {
  const result = await task()
  if (result instanceof Error) {
    // Result is Error
  } else {
    // Result is Resp
  }
})()