gcanti / typelevel-ts

Type level programming in TypeScript
https://gcanti.github.io/typelevel-ts
MIT License
356 stars 12 forks source link

Example for Option #1

Closed danielepolencic closed 6 years ago

danielepolencic commented 7 years ago

This looks very interesting, but I'm struggling to get my head around how to use Option.

Would you be able to provide an example, please?

gcanti commented 7 years ago

TOption is useful for type level computations that can fail, for example Sub

import { Sub, _1, _2, _3 } from 'typelevel-ts'

type A = Sub<_2, _1> // TSome<_1>

// -1 is not a Nat
type B = Sub<_2, _3> // TNone