@wishtack/get
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

@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

Package Sidebar

Install

npm i @wishtack/get

Weekly Downloads

0

Version

1.0.4

License

MIT

Unpacked Size

40.6 kB

Total Files

11

Last publish

Collaborators

  • wishtack-admin
  • yjaaidi