diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 9b4548502..78888f871 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -936,7 +936,20 @@ result = _.methods(_); result = <_.LoDashArrayWrapper>_(_).functions(); result = <_.LoDashArrayWrapper>_(_).methods(); -result = _.get({ 'a': 1, 'b': 2, 'c': 3 }, 'b'); +// _.get +result = _.get({ 'a': [{ 'b': { 'c': 3 } }] }, 'a[0].b.c'); +// → 3 +result = _.get({ 'a': [{ 'b': { 'c': 3 } }] }, ['a', '0', 'b', 'c']); +// → 3 +result = _.get({ 'a': [{ 'b': { 'c': 3 } }] }, 'a.b.c', 'default'); +// → 'default' + +result = _({ 'a': [{ 'b': { 'c': 3 } }] }).get('a[0].b.c'); +// → 3 +result = _({ 'a': [{ 'b': { 'c': 3 } }] }).get(['a', '0', 'b', 'c']); +// → 3 +result = _({ 'a': [{ 'b': { 'c': 3 } }] }).get('a.b.c', 'default'); +// → 'default' result = _.has({ 'a': 1, 'b': 2, 'c': 3 }, 'b'); diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index f02a4aa97..acb0adc42 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -5756,12 +5756,21 @@ declare module _ { * @param defaultValue The value returned if the resolved value is undefined. * @return Returns the resolved value. **/ - get(object : Object, - path:string|string[], + get(object: Object, + path: string|string[], defaultValue?:T ): T; } + interface LoDashObjectWrapper { + /** + * @see _.get + **/ + get(path: string|string[], + defaultValue?: TResult + ): TResult; + } + //_.has interface LoDashStatic { /**