项目作者: WuYifanX

项目描述 :
Typesafe Lodash Get
高级语言: TypeScript
项目地址: git://github.com/WuYifanX/safeGet.git
创建时间: 2019-08-02T14:19:30Z
项目社区:https://github.com/WuYifanX/safeGet

开源协议:MIT License

下载


SafeGet

Typesafe Lodash Get in TypeScript

Why safeGet

  1. safeGet handle type more easily than lodash get:
  1. const deepNestDataset = {
  2. first: {
  3. second: {
  4. third: "third"
  5. }
  6. }
  7. }
  8. // typeof resultByLodashGet is any
  9. const resultByLodashGet = _.get(deepNestDataset, "first.second.third")
  10. // with generic, type is correct
  11. const resultByLodashGetByGeneric = _.get<typeof deepNestDataset, "first", "second", "third">(deepNestDataset,
  12. ["first", "second", "third"])
  13. // typeof resultBySafeGet is correct
  14. const resultBySafeGet = safeGet(deepNestDataset, it => it.first.second.third)

How to install

How to use