Detalhes do pacote

defaults-deep-ts

wix-incubator1kMIT0.2.3

_.defaultsDeep with proper typescript typing

defaultsDeep, merge, typescript, ts

readme (leia-me)

defaults-deep-ts

Build Status

Similar to _.defaultsDeep but with some differences:

  • Intelligent TypeScript typings
  • Doesn't try to merge arrays
  • Doesn't allow multiple sources
  • Treats null as an empty value

Install

npm install defaults-deep-ts

Usage

// let's say you have some object where some fields are optional:
type SomeData = {
  order?: {
    id?: string
  };
}
const data: SomeData = {};

// You have to check for for undefined fields using `!` or `?`:
const id: string = data.order!.id!;

// Let's provide some defaults:
import defaultsDeep from 'defaults-deep-ts'
const dataWithDefaults = defaultsDeep(data, {order: {id: ''}});

// Now `order` and `id` are not optional bacause you provided defaults for them:
const id: string = dataWithDefaults.order.id;