lodash: changed _.property() method

This commit is contained in:
Ilya Mochalov
2015-08-15 22:18:59 +05:00
parent 5109e1269d
commit 7babb2704c
2 changed files with 31 additions and 6 deletions
+12
View File
@@ -1490,6 +1490,18 @@ result = <string>_.result(object, 'stuff');
var tempObject = {};
result = <typeof _>_.runInContext(tempObject);
// _.property
interface TestPropertyObject {
a: {
b: number;
}
}
var testPropertyObject: TestPropertyObject;
result = <number>_.property<TestPropertyObject, number>('a.b')(testPropertyObject);
result = <number>_.property<TestPropertyObject, number>(['a', 'b'])(testPropertyObject);
result = <number>(_('a.b').property<TestPropertyObject, number>().value())(testPropertyObject);
result = <number>(_(['a', 'b']).property<TestPropertyObject, number>().value())(testPropertyObject);
// _.propertyOf
interface TestPropertyOfObject {
a: {
+19 -6
View File
@@ -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<T,RT>(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<TObj, TResult>(path: string|string[]): (obj: TObj) => TResult;
}
interface LoDashStringWrapper {
/**
* @see _.property
*/
property<TObj, TResult>(): LoDashObjectWrapper<(obj: TObj) => TResult>;
}
interface LoDashArrayWrapper<T> {
/**
* @see _.property
*/
property<TObj, TResult>(): LoDashObjectWrapper<(obj: TObj) => TResult>;
}
//_.propertyOf