Skip to content

Latest commit

 

History

History
 
 

get

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

@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

@wishtack/get auto completion