typescript(option): chore: updated readme
Signed-off-by: prescientmoon <git@moonythm.dev>
This commit is contained in:
parent
470574fdad
commit
664a46319d
|
@ -4,6 +4,35 @@
|
||||||
|
|
||||||
# Option
|
# Option
|
||||||
|
|
||||||
|
Probably the most opinionated implementation of the Option type for typescript.
|
||||||
|
|
||||||
|
## Features:
|
||||||
|
|
||||||
|
- Large amount of helpers (curently 25), more than f#'s and elm's core libraries combined.
|
||||||
|
- Typesafe:
|
||||||
|
```ts
|
||||||
|
const foo0: Option<string> = None // works
|
||||||
|
const foo1: Option<string> = Some('foo1') // works
|
||||||
|
const foo2: Option<string> = 'foo2' // errors out
|
||||||
|
const foo3: Option<string> = null // errors out
|
||||||
|
const foo4: Option<string> = Some(4) // errors out
|
||||||
|
```
|
||||||
|
- Native equality:
|
||||||
|
```ts
|
||||||
|
Some(7) === Some(7) // true
|
||||||
|
Some(7) === Some(5) // false
|
||||||
|
Some(7) === None // false
|
||||||
|
```
|
||||||
|
|
||||||
|
## Limitations
|
||||||
|
|
||||||
|
Both limitaions bellow come from the lack of nominal-typing offered by typescript and are inherited from the `Brand` type offered by the [utility-types](https://github.com/piotrwitek/utility-types) library
|
||||||
|
|
||||||
|
- Due to the way the library works (using the `Brand`
|
||||||
|
type from [utility-types](https://github.com/piotrwitezutility-types)) `Some(4) === 4` will return true, similarly to how `4 == "4"` returns true (except in this libraries case the `===` operator will behave the same way).
|
||||||
|
- The inner value of `Option` cannot have a `__brand` prop
|
||||||
|
(well, tehnically it can but it would be overwritten by the `Brand` type from [utility-types](https://github.com/piotrwitek/utility-types))
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
|
@ -16,6 +45,8 @@ npm install @adrielus/option
|
||||||
|
|
||||||
For detailed usage read [the docs](https://github.com/Mateiadrielrafael/option/tree/master/docs/main.md)
|
For detailed usage read [the docs](https://github.com/Mateiadrielrafael/option/tree/master/docs/main.md)
|
||||||
|
|
||||||
|
> Note: The docs are still work in progress. Contributions are welcome:)
|
||||||
|
|
||||||
# Contributing
|
# Contributing
|
||||||
|
|
||||||
First, clone this repo:
|
First, clone this repo:
|
||||||
|
|
Loading…
Reference in a new issue