4.0.8 • Published 4 years ago
super-simple v4.0.8
Super Simple & Safe(r) types for TypeScript
Using TypeScript's strict
mode, null
and undefined
can no longer be used in an "unsafe" way.
Moreover, JavaScript now offers built-in operators, such as:
x ?? defaultValue
x?.propertyName
and
a?.[index]
analogous to <|>
and >>=
from Haskell.
Therefore, a Maybe
implementation is no longer necessary.
As for arrays, unfortunately TypeScript allows unsafe indexing:
a[-1]
is allowed and if a
is T[]
, the result is inferred to be of type T
, which is not always true...
So a safer List<T> = readonly Maybe<T>[]
type is provided, where Maybe<T> = T | undefined
.
Usage
Install via your package manager:
npm install super-simple
and use like so:
import { List } from "super-simple";
const a = List([1, 2, 3]);