1
Fork 0
solar-conflux/typescript/option
2019-12-25 16:33:05 +02:00
..
.github/workflows typescript(option): ci: run tests before releasing 2019-12-25 14:46:33 +02:00
.vscode typescript(option): chore: fixed readme docs url 2019-12-19 20:58:54 +02:00
docs typescript(option): docs: fixed the fromNullable section not beeing in the table of contents 2019-12-20 15:00:54 +02:00
src typescript(option): feat: added the 'oneOf' helper 2019-12-25 16:09:18 +02:00
test typescript(option): feat: added the 'oneOf' helper 2019-12-25 16:09:18 +02:00
.gitignore typescript(option): chore: added lib to gitignore 2019-12-23 16:07:00 +02:00
.prettierrc typescript(option): chore: initial setup 2019-12-19 12:37:48 +02:00
LICENSE typescript(option): chore: initial setup 2019-12-19 12:37:48 +02:00
package.json typescript(option): feat: added the 'orLazy' helper 2019-12-25 15:51:56 +02:00
pnpm-lock.yaml typescript(option): feat: added the 'orLazy' helper 2019-12-25 15:51:56 +02:00
README.md typescript(option): chore: updated readme 2019-12-25 16:25:30 +02:00
rollup.config.ts typescript(option): build: fixed rollup not reading tsconfig.json while emiting the declarations 2019-12-25 16:33:05 +02:00
tsconfig.json typescript(option): test: wrote tests for filter 2019-12-25 14:58:29 +02:00

npm (scoped) npm bundle size (scoped) forthebadge

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:
    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:
    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 library

  • Due to the way the library works (using the Brand type from utility-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)

Installation

npm install @adrielus/option

(There is also an amd build at /dist/bundle.amd.js which uses the Option namespace)

Usage

For detailed usage read the docs

Note: The docs are still work in progress. Contributions are welcome:)

Contributing

First, clone this repo:

git clone https://github.com/Mateiadrielrafael/option
cd option

Then use pnpm to install the dependencies:

pnpm install

You can use the build command to build the package (this is dont automatically by github actions):

pnpm run build