mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-08-28 12:43:06 +08:00
lodash: changed _.pick() method
This commit is contained in:
+14
-5
@@ -1594,11 +1594,20 @@ result = <HasName>_({ 'name': 'moe', 'age': 40 }).omit(function (value) {
|
||||
result = <any[][]>_.pairs({ 'moe': 30, 'larry': 40 });
|
||||
result = <any[][]>_({ 'moe': 30, 'larry': 40 }).pairs().value();
|
||||
|
||||
result = <HasName>_.pick({ 'name': 'moe', '_userid': 'moe1' }, 'name');
|
||||
result = <HasName>_.pick({ 'name': 'moe', '_userid': 'moe1' }, ['name']);
|
||||
result = <HasName>_.pick({ 'name': 'moe', '_userid': 'moe1' }, function (value, key) {
|
||||
return key.charAt(0) != '_';
|
||||
});
|
||||
// _.pick
|
||||
interface TestPickFn {
|
||||
(element: any, key: string, collection: any): boolean;
|
||||
}
|
||||
{
|
||||
let testPickFn: TestPickFn;
|
||||
let result: TResult;
|
||||
result = _.pick<TResult, Object>({}, 0, '1', true, [2], ['3'], [true], [4, '5', true]);
|
||||
result = _.pick<TResult, Object>({}, testPickFn);
|
||||
result = _.pick<TResult, Object>({}, testPickFn, any);
|
||||
result = _({}).pick<TResult>(0, '1', true, [2], ['3'], [true], [4, '5', true]).value();
|
||||
result = _({}).pick<TResult>(testPickFn).value();
|
||||
result = _({}).pick<TResult>(testPickFn, any).value();
|
||||
}
|
||||
|
||||
// _.set
|
||||
result = <{ a: { b: { c: number; }}[]}>_.set({ 'a': [{ 'b': { 'c': 3 } }] }, 'a[0].b.c', 4);
|
||||
|
||||
Vendored
+36
-22
@@ -7450,36 +7450,50 @@ declare module _ {
|
||||
pairs(): LoDashArrayWrapper<any[]>;
|
||||
}
|
||||
|
||||
//_.picks
|
||||
//_.pick
|
||||
interface LoDashStatic {
|
||||
/**
|
||||
* Creates a shallow clone of object composed of the specified properties. Property names may be
|
||||
* specified as individual arguments or as arrays of property names. If a callback is provided
|
||||
* it will be executed for each property of object picking the properties the callback returns
|
||||
* truey for. The callback is bound to thisArg and invoked with three arguments; (value, key,
|
||||
* object).
|
||||
* @param object Object to strip unwanted key/value pairs.
|
||||
* @param keys Property names to pick
|
||||
* @return An object composed of the picked properties.
|
||||
**/
|
||||
pick<Picked, T>(
|
||||
* Creates an object composed of the picked object properties. Property names may be specified as individual
|
||||
* arguments or as arrays of property names. If predicate is provided it’s invoked for each property of object
|
||||
* picking the properties predicate returns truthy for. The predicate is bound to thisArg and invoked with
|
||||
* three arguments: (value, key, object).
|
||||
*
|
||||
* @param object The source object.
|
||||
* @param predicate The function invoked per iteration or property names to pick, specified as individual
|
||||
* property names or arrays of property names.
|
||||
* @param thisArg The this binding of predicate.
|
||||
* @return An object composed of the picked properties.
|
||||
*/
|
||||
pick<TResult extends Object, T extends Object>(
|
||||
object: T,
|
||||
...keys: string[]): Picked;
|
||||
predicate: ObjectIterator<any, boolean>,
|
||||
thisArg?: any
|
||||
): TResult;
|
||||
|
||||
/**
|
||||
* @see _.pick
|
||||
**/
|
||||
pick<Picked, T>(
|
||||
* @see _.pick
|
||||
*/
|
||||
pick<TResult extends Object, T extends Object>(
|
||||
object: T,
|
||||
keys: string[]): Picked;
|
||||
...predicate: Array<string|number|boolean|Array<string|number|boolean>>
|
||||
): TResult;
|
||||
}
|
||||
|
||||
interface LoDashObjectWrapper<T> {
|
||||
/**
|
||||
* @see _.pick
|
||||
*/
|
||||
pick<TResult extends Object>(
|
||||
predicate: ObjectIterator<any, boolean>,
|
||||
thisArg?: any
|
||||
): LoDashObjectWrapper<TResult>;
|
||||
|
||||
/**
|
||||
* @see _.pick
|
||||
**/
|
||||
pick<Picked, T>(
|
||||
object: T,
|
||||
callback: ObjectIterator<any, boolean>,
|
||||
thisArg?: any): Picked;
|
||||
* @see _.pick
|
||||
*/
|
||||
pick<TResult extends Object>(
|
||||
...predicate: Array<string|number|boolean|Array<string|number|boolean>>
|
||||
): LoDashObjectWrapper<TResult>;
|
||||
}
|
||||
|
||||
//_.set
|
||||
|
||||
Reference in New Issue
Block a user