DEV Community

Discussion on: fp-ts and Beautiful API Calls

Collapse
 
nunzio profile image
Chris Pizzurro

Great post! Had a little trouble with the code as written -- might be my Typescript config or some update to fp-ts. Had to provide type arguments to flow of decodeWith due to an "Type argument cannot be inferred from usage" error. Once decodeWith was changed to the following, it all worked:

const decodeWith = <A>(decoder: t.Decoder<unknown, A>) =>
  flow<Array<A>,Validation<A>, E.Either<Error, A>, TE.TaskEither<Error, A>>(
    decoder.decode,
    E.mapLeft(errors => new Error(failure(errors as Array<ValidationError>).join('\n'))),
    TE.fromEither
  )
Enter fullscreen mode Exit fullscreen mode

Thank you!