diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 8366f75fca..54f79ed762 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -8823,6 +8823,101 @@ module TestInvert { } } +// _.invertBy +namespace TestInvertBy { + let array: ({a: number;})[]; + let list: _.List<{a: number;}>; + let dictionary: _.Dictionary<{a: number;}>; + let numericDictionary: _.NumericDictionary<{a: number;}>; + + let stringIterator: (value: string) => any; + let arrayIterator: (value: {a: number;}) => any; + let listIterator: (value: {a: number;}) => any; + let dictionaryIterator: (value: {a: number;}) => any; + let numericDictionaryIterator: (value: {a: number;}) => any; + + { + let result: _.Dictionary; + + result = _.invertBy('foo'); + result = _.invertBy('foo', stringIterator); + + result = _.invertBy(array); + result = _.invertBy<{a: number;}>(array, 'a'); + result = _.invertBy<{a: number;}>(array, arrayIterator); + result = _.invertBy<{a: number;}>(array, {a: 1}); + + result = _.invertBy(list); + result = _.invertBy<{a: number;}>(list, 'a'); + result = _.invertBy<{a: number;}>(list, listIterator); + result = _.invertBy<{a: number;}>(list, {a: 1}); + + result = _.invertBy(dictionary); + result = _.invertBy<{a: number;}>(dictionary, 'a'); + result = _.invertBy<{a: number;}>(dictionary, dictionaryIterator); + result = _.invertBy<{a: number;}>(dictionary, {a: 1}); + + result = _.invertBy(numericDictionary); + result = _.invertBy<{a: number;}>(numericDictionary, 'a'); + result = _.invertBy<{a: number;}>(numericDictionary, numericDictionaryIterator); + result = _.invertBy<{a: number;}>(numericDictionary, {a: 1}); + } + + { + let result: _.LoDashImplicitObjectWrapper<_.Dictionary>; + + result = _('foo').invertBy(); + result = _('foo').invertBy(stringIterator); + + result = _(array).invertBy(); + result = _(array).invertBy('a'); + result = _(array).invertBy(arrayIterator); + result = _(array).invertBy({a: 1}); + + result = _(list).invertBy(); + result = _(list).invertBy('a'); + result = _(list).invertBy(listIterator); + result = _(list).invertBy<{a: number;}>({a: 1}); + + result = _(dictionary).invertBy(); + result = _(dictionary).invertBy('a'); + result = _(dictionary).invertBy(dictionaryIterator); + result = _(dictionary).invertBy<{a: number;}>({a: 1}); + + result = _(numericDictionary).invertBy(); + result = _(numericDictionary).invertBy('a'); + result = _(numericDictionary).invertBy(numericDictionaryIterator); + result = _(numericDictionary).invertBy<{a: number;}>({a: 1}); + } + + { + let result: _.LoDashExplicitObjectWrapper<_.Dictionary>; + + result = _('foo').chain().invertBy(); + result = _('foo').chain().invertBy(stringIterator); + + result = _(array).chain().invertBy(); + result = _(array).chain().invertBy('a'); + result = _(array).chain().invertBy(arrayIterator); + result = _(array).chain().invertBy({a: 1}); + + result = _(list).chain().invertBy(); + result = _(list).chain().invertBy('a'); + result = _(list).chain().invertBy(listIterator); + result = _(list).chain().invertBy<{a: number;}>({a: 1}); + + result = _(dictionary).chain().invertBy(); + result = _(dictionary).chain().invertBy('a'); + result = _(dictionary).chain().invertBy(dictionaryIterator); + result = _(dictionary).chain().invertBy<{a: number;}>({a: 1}); + + result = _(numericDictionary).chain().invertBy(); + result = _(numericDictionary).chain().invertBy('a'); + result = _(numericDictionary).chain().invertBy(numericDictionaryIterator); + result = _(numericDictionary).chain().invertBy<{a: number;}>({a: 1}); + } +} + // _.keys module TestKeys { let object: _.Dictionary; diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index b77598f138..df704825c8 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -14951,6 +14951,133 @@ declare module _ { invert(multiValue?: boolean): LoDashExplicitObjectWrapper; } + //_.inverBy + interface InvertByIterator { + (value: T): any; + } + + interface LoDashStatic { + /** + * This method is like _.invert except that the inverted object is generated from the results of running each + * element of object through iteratee. The corresponding inverted value of each inverted key is an array of + * keys responsible for generating the inverted value. The iteratee is invoked with one argument: (value). + * + * @param object The object to invert. + * @param interatee The iteratee invoked per element. + * @return Returns the new inverted object. + */ + invertBy( + object: Object, + interatee?: InvertByIterator|string + ): Dictionary; + + /** + * @see _.invertBy + */ + invertBy( + object: _.Dictionary|_.NumericDictionary, + interatee?: InvertByIterator|string + ): Dictionary; + + /** + * @see _.invertBy + */ + invertBy( + object: Object, + interatee?: W + ): Dictionary; + + /** + * @see _.invertBy + */ + invertBy( + object: _.Dictionary, + interatee?: W + ): Dictionary; + } + + interface LoDashImplicitWrapper { + /** + * @see _.invertBy + */ + invertBy( + interatee?: InvertByIterator + ): LoDashImplicitObjectWrapper>; + } + + interface LoDashImplicitArrayWrapper { + /** + * @see _.invertBy + */ + invertBy( + interatee?: InvertByIterator|string + ): LoDashImplicitObjectWrapper>; + + /** + * @see _.invertBy + */ + invertBy( + interatee?: W + ): LoDashImplicitObjectWrapper>; + } + + interface LoDashImplicitObjectWrapper { + /** + * @see _.invertBy + */ + invertBy( + interatee?: InvertByIterator|string + ): LoDashImplicitObjectWrapper>; + + /** + * @see _.invertBy + */ + invertBy( + interatee?: W + ): LoDashImplicitObjectWrapper>; + } + + interface LoDashExplicitWrapper { + /** + * @see _.invertBy + */ + invertBy( + interatee?: InvertByIterator + ): LoDashExplicitObjectWrapper>; + } + + interface LoDashExplicitArrayWrapper { + /** + * @see _.invertBy + */ + invertBy( + interatee?: InvertByIterator|string + ): LoDashExplicitObjectWrapper>; + + /** + * @see _.invertBy + */ + invertBy( + interatee?: W + ): LoDashExplicitObjectWrapper>; + } + + interface LoDashExplicitObjectWrapper { + /** + * @see _.invertBy + */ + invertBy( + interatee?: InvertByIterator|string + ): LoDashExplicitObjectWrapper>; + + /** + * @see _.invertBy + */ + invertBy( + interatee?: W + ): LoDashExplicitObjectWrapper>; + } + //_.keys interface LoDashStatic { /**