3 ms·
Yes it's terrible naming. The more abstract the naming, the harder it is to reason about. Plus, JS/TS already have proper union types without a need for a const
by boubiyeah 7y ago
Yes it's terrible naming. The more abstract the naming, the harder it is to reason about.
Plus, JS/TS already have proper union types without a need for a construct like Either.
A better naming for 99% of cases is (like found in Elm)
type Result error value
= Ok value
| Err error
- lacampbell 7y agoPlus, JS/TS already have proper union types without a need for a construct like Either. I disagree - what if on success it returns a string representing some data, and on failure it returns a string detailing the error? A `string | string` return type is not very useful, while an `Either<string, string>` is IMO.
- boubiyeah 7y agoBut that's the simplest union type. You could have: type Result = {type: 'ok', value: string} | {type: 'err', value: string}