diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 983d73f21..4b06f98b0 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -8640,8 +8640,6 @@ module TestOmit { result = _.omit({}, 0, 'a'); result = _.omit({}, true, 0, 'a'); result = _.omit({}, ['b', 1, false], true, 0, 'a'); - result = _.omit({}, predicate); - result = _.omit({}, predicate, any); } { @@ -8651,8 +8649,6 @@ module TestOmit { result = _({}).omit(0, 'a'); result = _({}).omit(true, 0, 'a'); result = _({}).omit(['b', 1, false], true, 0, 'a'); - result = _({}).omit(predicate); - result = _({}).omit(predicate, any); } { @@ -8662,8 +8658,29 @@ module TestOmit { result = _({}).chain().omit(0, 'a'); result = _({}).chain().omit(true, 0, 'a'); result = _({}).chain().omit(['b', 1, false], true, 0, 'a'); - result = _({}).chain().omit(predicate); - result = _({}).chain().omit(predicate, any); + } +} + +// _.omitBy +module TestOmitBy { + let predicate: (element: any, key: string, collection: any) => boolean; + + { + let result: TResult; + + result = _.omitBy({}, predicate); + } + + { + let result: _.LoDashImplicitObjectWrapper; + + result = _({}).omitBy(predicate); + } + + { + let result: _.LoDashExplicitObjectWrapper; + + result = _({}).chain().omitBy(predicate); } } @@ -8719,8 +8736,6 @@ module TestPick { result = _.pick({}, 0, 'a'); result = _.pick({}, true, 0, 'a'); result = _.pick({}, ['b', 1, false], true, 0, 'a'); - result = _.pick({}, predicate); - result = _.pick({}, predicate, any); } { @@ -8730,8 +8745,6 @@ module TestPick { result = _({}).pick(0, 'a'); result = _({}).pick(true, 0, 'a'); result = _({}).pick(['b', 1, false], true, 0, 'a'); - result = _({}).pick(predicate); - result = _({}).pick(predicate, any); } { @@ -8741,8 +8754,29 @@ module TestPick { result = _({}).chain().pick(0, 'a'); result = _({}).chain().pick(true, 0, 'a'); result = _({}).chain().pick(['b', 1, false], true, 0, 'a'); - result = _({}).chain().pick(predicate); - result = _({}).chain().pick(predicate, any); + } +} + +// _.pickBy +module TestPickBy { + let predicate: (element: any, key: string, collection: any) => boolean; + + { + let result: TResult; + + result = _.pickBy({}, predicate); + } + + { + let result: _.LoDashImplicitObjectWrapper; + + result = _({}).pickBy(predicate); + } + + { + let result: _.LoDashExplicitObjectWrapper; + + result = _({}).chain().pickBy(predicate); } } diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index f4f34bfc7..818c28076 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -30,7 +30,7 @@ TODO: - [x] Split _.indexOf & _.lastIndexOf into _.sortedIndexOf & _.sortedLastIndexOf - [x] Split _.max & _.min into _.maxBy & _.minBy -- [ ] Split _.omit & _.pick into _.omitBy & _.pickBy +- [x] Split _.omit & _.pick into _.omitBy & _.pickBy - [ ] Split _.sample into _.sampleSize - [ ] Split _.sortedIndex into _.sortedIndexBy - [ ] Split _.sortedLastIndex into _.sortedLastIndexBy @@ -13334,24 +13334,24 @@ declare module _ { //_.omit interface LoDashStatic { /** - * The opposite of _.pick; this method creates an object composed of the own and inherited enumerable - * properties of object that are not omitted. + * The opposite of `_.pick`; this method creates an object composed of the + * own and inherited enumerable properties of `object` that are not omitted. * - * @param object The source object. - * @param predicate The function invoked per iteration or property names to omit, specified as individual - * property names or arrays of property names. - * @param thisArg The this binding of predicate. - * @return Returns the new object. + * @static + * @memberOf _ + * @category Object + * @param {Object} object The source object. + * @param {...(string|string[])} [props] The property names to omit, specified + * individually or in arrays.. + * @returns {Object} Returns the new object. + * @example + * + * var object = { 'a': 1, 'b': '2', 'c': 3 }; + * + * _.omit(object, ['a', 'c']); + * // => { 'b': '2' } */ - omit( - object: T, - predicate: ObjectIterator, - thisArg?: any - ): TResult; - /** - * @see _.omit - */ omit( object: T, ...predicate: (StringRepresentable|StringRepresentable[])[] @@ -13359,13 +13359,6 @@ declare module _ { } interface LoDashImplicitObjectWrapper { - /** - * @see _.omit - */ - omit( - predicate: ObjectIterator, - thisArg?: any - ): LoDashImplicitObjectWrapper; /** * @see _.omit @@ -13376,13 +13369,6 @@ declare module _ { } interface LoDashExplicitObjectWrapper { - /** - * @see _.omit - */ - omit( - predicate: ObjectIterator, - thisArg?: any - ): LoDashExplicitObjectWrapper; /** * @see _.omit @@ -13392,6 +13378,50 @@ declare module _ { ): LoDashExplicitObjectWrapper; } + //_.omitBy + interface LoDashStatic { + /** + * The opposite of `_.pickBy`; this method creates an object composed of the + * own and inherited enumerable properties of `object` that `predicate` + * doesn't return truthy for. + * + * @static + * @memberOf _ + * @category Object + * @param {Object} object The source object. + * @param {Function|Object|string} [predicate=_.identity] The function invoked per property. + * @returns {Object} Returns the new object. + * @example + * + * var object = { 'a': 1, 'b': '2', 'c': 3 }; + * + * _.omitBy(object, _.isNumber); + * // => { 'b': '2' } + */ + omitBy( + object: T, + predicate: ObjectIterator + ): TResult; + } + + interface LoDashImplicitObjectWrapper { + /** + * @see _.omitBy + */ + omitBy( + predicate: ObjectIterator + ): LoDashImplicitObjectWrapper; + } + + interface LoDashExplicitObjectWrapper { + /** + * @see _.omitBy + */ + omitBy( + predicate: ObjectIterator + ): LoDashExplicitObjectWrapper; + } + //_.toPairs interface LoDashStatic { /** @@ -13422,25 +13452,21 @@ declare module _ { //_.pick interface LoDashStatic { /** - * 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). + * Creates an object composed of the picked `object` properties. * - * @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 Returns the new object. - */ - pick( - object: T, - predicate: ObjectIterator, - thisArg?: any - ): TResult; - - /** - * @see _.pick + * @static + * @memberOf _ + * @category Object + * @param {Object} object The source object. + * @param {...(string|string[])} [props] The property names to pick, specified + * individually or in arrays. + * @returns {Object} Returns the new object. + * @example + * + * var object = { 'a': 1, 'b': '2', 'c': 3 }; + * + * _.pick(object, ['a', 'c']); + * // => { 'a': 1, 'c': 3 } */ pick( object: T, @@ -13449,14 +13475,6 @@ declare module _ { } interface LoDashImplicitObjectWrapper { - /** - * @see _.pick - */ - pick( - predicate: ObjectIterator, - thisArg?: any - ): LoDashImplicitObjectWrapper; - /** * @see _.pick */ @@ -13466,14 +13484,6 @@ declare module _ { } interface LoDashExplicitObjectWrapper { - /** - * @see _.pick - */ - pick( - predicate: ObjectIterator, - thisArg?: any - ): LoDashExplicitObjectWrapper; - /** * @see _.pick */ @@ -13482,6 +13492,49 @@ declare module _ { ): LoDashExplicitObjectWrapper; } + //_.pickBy + interface LoDashStatic { + /** + * Creates an object composed of the `object` properties `predicate` returns + * truthy for. The predicate is invoked with one argument: (value). + * + * @static + * @memberOf _ + * @category Object + * @param {Object} object The source object. + * @param {Function|Object|string} [predicate=_.identity] The function invoked per property. + * @returns {Object} Returns the new object. + * @example + * + * var object = { 'a': 1, 'b': '2', 'c': 3 }; + * + * _.pickBy(object, _.isNumber); + * // => { 'a': 1, 'c': 3 } + */ + pickBy( + object: T, + predicate: ObjectIterator + ): TResult; + } + + interface LoDashImplicitObjectWrapper { + /** + * @see _.pickBy + */ + pickBy( + predicate: ObjectIterator + ): LoDashImplicitObjectWrapper; + } + + interface LoDashExplicitObjectWrapper { + /** + * @see _.pickBy + */ + pickBy( + predicate: ObjectIterator + ): LoDashExplicitObjectWrapper; + } + //_.result interface LoDashStatic { /**