https://github.com/oliverbrotchie/optionals
Rust-like error handling and options for TypeScript and Deno!
https://github.com/oliverbrotchie/optionals
deno error-handling rust typescript
Last synced: 4 months ago
JSON representation
Rust-like error handling and options for TypeScript and Deno!
- Host: GitHub
- URL: https://github.com/oliverbrotchie/optionals
- Owner: OliverBrotchie
- License: mit
- Created: 2021-09-23T20:55:28.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-09-09T16:05:31.000Z (almost 2 years ago)
- Last Synced: 2025-11-20T22:07:37.393Z (7 months ago)
- Topics: deno, error-handling, rust, typescript
- Language: TypeScript
- Homepage:
- Size: 130 KB
- Stars: 194
- Watchers: 2
- Forks: 7
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Optionals
Rust-like error handling and options for TypeScript, Node and Deno!
This module allows you to remove `null` and `undefined` from your projects with the help of ES6 Symbols and helper methods. Inspired by Rust's `Option`, `Result` enums.
## Why should you use Optionals?
The standard practice of returning `null` or `undefined` when no other value can be returned means that there is no simple way to express the difference between a function that has returned "nothing" and a `null` return type. There are also no easy ways to handle errors in a functional pattern. Rust's implementation of `Option` and `Result` guarantees correctness by expressly forcing correct result-handling practices.
This module provides a minimal, fast and simple way to create expressive functions and perform better pattern matching on resulting values! 🚀
## Usage
```ts
// Result
import { Result, Ok, Err } from "https://deno.land/x/optionals@v2.0.2/mod.ts";
// Option
import {
Option,
Some,
None,
} from "https://deno.land/x/optionals@v2.0.2/mod.ts";
```
## Documentation
Please find further documentation on the [doc](https://doc.deno.land/https://deno.land/x/optionals@v2.0.2/mod.ts) page!