Skip to content
This repository has been archived by the owner on Nov 11, 2020. It is now read-only.

WuYifanX/safeGet

Repository files navigation

SafeGet

Typesafe Lodash Get in TypeScript

Why safeGet

  1. safeGet handle type more easily than lodash get:
const deepNestDataset = {
  first: {
    second: {
      third: "third"
    }
  }
}

// typeof resultByLodashGet is any
const resultByLodashGet = _.get(deepNestDataset, "first.second.third")
// with generic, type is correct
const resultByLodashGetByGeneric = _.get<typeof deepNestDataset, "first", "second", "third">(deepNestDataset,
 ["first", "second", "third"])

// typeof resultBySafeGet is correct
const resultBySafeGet = safeGet(deepNestDataset, it => it.first.second.third)

How to install

How to use

Releases

No releases published

Packages

No packages published