Explicitly
is a TypeScript library inspired by Rust that introduces Option and Result<T, E>. These types eliminate null, undefined, and unexpected exceptions by enforcing explicit handling of missing values and errors. With a functional approach, explicit enhances code robustness and readability while offering intuitive methods such as unwrapOr(), map(), and isOk().
Whether you're dealing with uncertain data, handling API errors, or preventing crashes due to missing values, Explicitly
provides a safe and elegant alternative to traditional error-handling practices in JavaScript and TypeScript.
This library implements two generic types:
- Option<T>: stands for a real that can exist (Some<T>) or be absent (None).
- Result<T, E>: stands for either a successful value (Ok<T>) or an error (Err<E>).
It is a safer alternative to null (the billion-dollar mistake) and undefined.
None, represents the absence of a value and forces the developer to handle this case explicitly.
Some<T> contains a value and provides method to handle it.
It is an alternative to throw new Error()
and involve to handle errors explicitly.
Ok<T> contains a successfull value, and provides methods to handle it.
Err<E> contains an error and prevents use without verification.