0.1.2 • Published 6 years ago

optional-chain-proxy v0.1.2

Weekly downloads
1
License
MIT
Repository
-
Last release
6 years ago

optional-chain-proxy travis-ci

Optional chain access implementation in TypeScript.
Uses Proxy API

Install

npm install optional-chain-proxy

Usage

import { optional } from "optional-chain-proxy";

type User {
  name?: {
    first: string
  }
}
const user: User = getUser(); // { name: null }
const optionalUser = optional(user);
optionalUser.name.first; // undefined, does not throw an exception.

API

optional-chain-proxy exports optional function. optional function lets a target object or an array and return the object which does not throw an exception even if accessing to null or undefined values.

optional

optional<T>(object: T) :: T

License

MIT