Handling Type Errors in Safe Data Transformation with TypeScript

I have a type error that's probably due to me doing something wrong.
I'm trying to do some safe data transformation. At the first line I've validated that query.results.rows is an Array<Schema.Unknown> and I expect it to have a single item at this point, but I don't know so I wrap it in an Option, then I want to to decode it to a particular row type, so I do a match on the option and, if it's some it becomes the
Either
returned by the Schema.decode call, or if none, I turn it into an Either.left.
The problem with this is that the type of the value becomes:
Either.Either<never, string> | Either.Either<{...}, ParseError> so the type is the union of my branch types, and then when I map over it the value becomes never | {...} and typescript complins.
I guess my broader question is how do I pipe these sort of data transformations and collect the left side, because my first attempt when I tried to use map most of the time resulted in me having nested Either or an Either nested in an Option which doesn't feel great. I hope this makes sense 😄
image.png
Was this page helpful?