1.0.4 • Published 6 years ago

@wishtack/get v1.0.4

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

@wishtack/get

@wishtack/get is a TypeScript typed functional alternative to Optional Chaining Operator (a.k.a. Safe Navigation Operator).

Installation

yarn add @wishtack/get

or

npm install --save @wishtack/get

Usage

import { get } from '@wishtack/get';

interface User {
    name: string;
    address?: {
        postalCode: string;
        street: string;
    };
}

const user: User = {
    name: 'Foo BAR'
};

get(user, 'address', 'postalCode'); // -> undefined

get(user, 'address', 'code'); // -> Compile time error

// playground.ts: - error TS2345: Argument of type '"code"' is not assignable to parameter of type '"postalCode" | "street"'.
//
// console.log(get(user, 'address', 'code'));
//                                 ~~~~~~~~

Enjoy type inference and get auto-completion for free