Options
All
  • Public
  • Public/Protected
  • All
Menu

External module "optional"

Index

Type aliases

Object literals

Type aliases

IOptional

IOptional: object & T

Optional type wrapper that uses proxies for short curcuiting evaluation of deeply nested nullable properties. This is something like elvis operator in Swift/Kotlin/Rust where you can write

if (a.b?.c == null) { ... }
example

type T = { x?: { y?: { z?: number } } }

const t = Optional.make<T>({});
console.log(x.y.z.valueOf()); // null
console.log(x.y.valueOf()); // null

const t1 = Optional.of({
  x: {
    y: {
      z: 10
    }
  }
})
console.log(x.y.z.valueOf()); // 10

Object literals

Const Optional

Optional: object

of

  • of<T>(t: T): object & T
  • Type parameters

    • T

    Parameters

    • t: T

    Returns object & T

Generated using TypeDoc