Skip to content

How to declare Either type? #4873

Closed Answered by Hi-Angel
Hi-Angel asked this question in Q&A
Discussion options

You must be logged in to vote

Found an answer: turns out, Either is simultaneously a module and a type. So the type does exist, it's just declared elsewhere.

Solution here:

export type ErrorOr<T> = Either.Either<string, T>;

Yeah, it is inconvenient to have to type Either twice, you might want to redefine it type TEither<E,V> = Either.Either<E,V>; or some such.


UPD: oh, here's a funny thing for you: turns out, the above isn't entirely correct, because in the library right values are left and left values are right. Leaving out the fix as an exercise to the reader.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Hi-Angel
Comment options

Answer selected by Hi-Angel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant