-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
20 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
type Left<T> = { | ||
error: T | ||
result?: never | ||
} | ||
|
||
type Right<U> = { | ||
error?: never | ||
result: U | ||
} | ||
|
||
/** | ||
* Either is a functional programming type which is used to communicate errors happening in potentially recoverable scenarios. | ||
* It can return either an error (Left side) or a resolved result (Right side), but not both. | ||
* It is up to caller of the function to handle received error or throw (Public)NonRecoverableError if it cannot. | ||
* | ||
* @see {@link https://antman-does-software.com/stop-catching-errors-in-typescript-use-the-either-type-to-make-your-code-predictable Further reading on motivation for Either type} | ||
*/ | ||
export type Either<T, U> = NonNullable<Left<T> | Right<U>> |