diff --git a/src/utils/flat/get.spec.ts b/src/utils/flat/get.spec.ts index 75a092a1d..a48a9cb1e 100644 --- a/src/utils/flat/get.spec.ts +++ b/src/utils/flat/get.spec.ts @@ -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', diff --git a/src/utils/flat/get.ts b/src/utils/flat/get.ts index 30774a068..5c549338b 100644 --- a/src/utils/flat/get.ts +++ b/src/utils/flat/get.ts @@ -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] }