A Typesafe extract / get method

Usage no npm install needed!

<script type="module">
  import extractTs from 'https://cdn.skypack.dev/extract-ts';



code style: prettier tested with: jest tested with: jest

This library is a type safe alternative to lodash's get.

Setup   API Documentation   Local Development  

The main advantage of this version is that it allows accessing many nested optional layers.
This library expects you to be using typescript 2.8.0, or above.


Install via npm (or yarn)

npm i extract-ts --save

After that you may use it:

const resultWithDefault: string = extract(
    testObject,                  // object you want to extract a value of
    obj => obj.data.desiredData, // extract the value
    ''                           // default value, optional parameter

// if you omit the default value, extract may also return undefined
const resultWithoutDefault: string | undefined = extract(testObject, obj => obj.data.desiredData);

// per default the type of the default value equals the result type of the extractor
// but you can change that wen you specify the types:
const result: string | number = <SomeTypeYouWantToAccess, string, number>(
    obj => obj.data.desiredData,

Local Development

After checking out the repository, you just need to run npm install.
You will find many useful commands in the table below.

Useful commands

npm command description
npm run build productive build of this library
npm run test runs all unit tests of this library
npm run test:coverage runs unit tests and evaluates the coverage
npm run verify checks test coverage and runs the linter
npm run lint runs tslint


Please follow the following steps if you want to contribute:

  • ( create an issue, introducing the change )
  • assign yourself to the issue you want to work on
  • open a pullrequest with your changes