From 7babb2704cd547042d01d73c7c341074469d163b Mon Sep 17 00:00:00 2001 From: Ilya Mochalov Date: Sat, 15 Aug 2015 22:18:59 +0500 Subject: [PATCH] lodash: changed _.property() method --- lodash/lodash-tests.ts | 12 ++++++++++++ lodash/lodash.d.ts | 25 +++++++++++++++++++------ 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 9d87e2a37..546e338bf 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -1490,6 +1490,18 @@ result = _.result(object, 'stuff'); var tempObject = {}; result = _.runInContext(tempObject); +// _.property +interface TestPropertyObject { + a: { + b: number; + } +} +var testPropertyObject: TestPropertyObject; +result = _.property('a.b')(testPropertyObject); +result = _.property(['a', 'b'])(testPropertyObject); +result = (_('a.b').property().value())(testPropertyObject); +result = (_(['a', 'b']).property().value())(testPropertyObject); + // _.propertyOf interface TestPropertyOfObject { a: { diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index b2603ee95..b5fa0d479 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -7397,12 +7397,25 @@ declare module _ { //_.property interface LoDashStatic { /** - * # S - * Creates a "_.pluck" style function, which returns the key value of a given object. - * @param key (string) - * @return the value of that key on the object - **/ - property(key: string): (obj: T) => RT; + * Creates a function that returns the property value at path on a given object. + * @param path The path of the property to get. + * @return Returns the new function. + */ + property(path: string|string[]): (obj: TObj) => TResult; + } + + interface LoDashStringWrapper { + /** + * @see _.property + */ + property(): LoDashObjectWrapper<(obj: TObj) => TResult>; + } + + interface LoDashArrayWrapper { + /** + * @see _.property + */ + property(): LoDashObjectWrapper<(obj: TObj) => TResult>; } //_.propertyOf