-
This is like a basic question, but it surprisingly doesn't seem to have an obvious answer. There's good usage documentation, but… it's more like "JavaScript usage", not "TypeScript usage" if you know what I mean, despite being a TypeScript lib. So, I'm just starting up with the lib, and my older code had: export type ErrorOr<T> = { isError: true; error: string } | { isError: false; val: T }; I am replacing it to seemingly obvious: export type ErrorOr<T> = Either<string, T>; And I get shared/Utils.ts:9:26 - error TS2709: Cannot use namespace 'Either' as a type.
9 export type ErrorOr<T> = Either<string, T>; Navigating to the sources shows that there're types |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Found an answer: turns out, Solution here: export type ErrorOr<T> = Either.Either<string, T>; Yeah, it is inconvenient to have to type 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. |
Beta Was this translation helpful? Give feedback.
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:
Yeah, it is inconvenient to have to type
Either
twice, you might want to redefine ittype 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.