Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/rakannimer/typesafe-get

Safely drill for nested values
https://github.com/rakannimer/typesafe-get

Last synced: 7 days ago
JSON representation

Safely drill for nested values

Awesome Lists containing this project

README

        

## typesafe-get

Safely drill for nested values

## Install

```sh
yarn add typesafe-get
```

## Usage

```typescript
import get from "ts-typesafe-get";

const obj = { a: 1, b: 2 };
const undef = undefined;
expect(get(() => obj.b, -1)).toEqual(2);
expect(get(() => obj.c, -1)).toEqual(-1);
expect(get(() => obj.a, -1)).toEqual(1);
expect(get(() => undef.a[0].b, -1)).toEqual(-1);

```

## API

### Signature :

```typescript
function get(
reducer: () => O,
defaultTo: Exclude
): Exclude;
```