Skip to content

Commit

Permalink
fix: error when passing prop: undefined
Browse files Browse the repository at this point in the history
before it was changed to [undefined]
  • Loading branch information
wojtek-krysiak committed Oct 16, 2020
1 parent 061bdf7 commit 748d2ee
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/utils/flat/get.spec.ts
Expand Up @@ -32,6 +32,12 @@ describe('module:flat.get', () => {
expect(get(params, 'nameNotExisting')).to.be.undefined
})

it('returns undefined for property set to undefined', () => {
expect(get({
property: undefined as any,
}, 'property')).to.be.undefined
})

it('returns nested array', () => {
expect(get(params, 'interest.OfMe')).to.deep.equal([
'javascript',
Expand Down
5 changes: 4 additions & 1 deletion src/utils/flat/get.ts
Expand Up @@ -19,7 +19,10 @@ const get = (params: FlattenParams = {}, propertyPath?: string): any => {
return unflatten(params)
}

if (typeof params[propertyPath] !== 'undefined') {
// when object has this key - simply return it
// we cannot rely on typeof params[propertyPath !== 'undefined' because params can actually be
// undefined and in such case if would pass and function would return [undefined]
if (Object.keys(params).find(key => (key === propertyPath))) {
return params[propertyPath]
}

Expand Down

0 comments on commit 748d2ee

Please sign in to comment.