mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-09 11:13:57 +08:00
Merge pull request #7493 from chrootsu/lodash-indexBy
lodash: signatures of _.indexBy have been changed
This commit is contained in:
+144
-3
@@ -4390,9 +4390,150 @@ module TestIncludes {
|
||||
}
|
||||
}
|
||||
|
||||
result = <_.Dictionary<IKey>>_.indexBy(keys, 'dir');
|
||||
result = <_.Dictionary<IKey>>_.indexBy(keys, function (key) { return String.fromCharCode(key.code); });
|
||||
result = <_.Dictionary<IKey>>_.indexBy(keys, function (key) { this.fromCharCode(key.code); }, String);
|
||||
// _.indexBy
|
||||
module TestIndexBy {
|
||||
type SampleObject = {a: number; b: string; c: boolean;};
|
||||
|
||||
let array: SampleObject[];
|
||||
let list: _.List<SampleObject>;
|
||||
let dictionary: _.Dictionary<SampleObject>;
|
||||
let numericDictionary: _.NumericDictionary<SampleObject>;
|
||||
|
||||
let stringIterator: (value: string, index: number, collection: string) => any;
|
||||
let listIterator: (value: SampleObject, index: number, collection: _.List<SampleObject>) => any;
|
||||
let dictionaryIterator: (value: SampleObject, key: string, collection: _.Dictionary<SampleObject>) => any;
|
||||
let numericDictionaryIterator: (value: SampleObject, key: number, collection: _.NumericDictionary<SampleObject>) => any;
|
||||
|
||||
{
|
||||
let result: _.Dictionary<string>;
|
||||
|
||||
result = _.indexBy<string>('abcd');
|
||||
result = _.indexBy<string>('abcd', stringIterator);
|
||||
result = _.indexBy<string>('abcd', stringIterator, any);
|
||||
}
|
||||
|
||||
{
|
||||
let result: _.Dictionary<SampleObject>;
|
||||
|
||||
result = _.indexBy<SampleObject>(array);
|
||||
result = _.indexBy<SampleObject>(array, listIterator);
|
||||
result = _.indexBy<SampleObject>(array, listIterator, any);
|
||||
result = _.indexBy<SampleObject>(array, 'a');
|
||||
result = _.indexBy<SampleObject>(array, 'a', any);
|
||||
result = _.indexBy<{a: number}, SampleObject>(array, {a: 42});
|
||||
result = _.indexBy<SampleObject>(array, {a: 42});
|
||||
|
||||
result = _.indexBy<SampleObject>(list);
|
||||
result = _.indexBy<SampleObject>(list, listIterator);
|
||||
result = _.indexBy<SampleObject>(list, listIterator, any);
|
||||
result = _.indexBy<SampleObject>(list, 'a');
|
||||
result = _.indexBy<SampleObject>(list, 'a', any);
|
||||
result = _.indexBy<{a: number}, SampleObject>(list, {a: 42});
|
||||
result = _.indexBy<SampleObject>(list, {a: 42});
|
||||
|
||||
result = _.indexBy<SampleObject>(numericDictionary);
|
||||
result = _.indexBy<SampleObject>(numericDictionary, numericDictionaryIterator);
|
||||
result = _.indexBy<SampleObject>(numericDictionary, numericDictionaryIterator, any);
|
||||
result = _.indexBy<SampleObject>(numericDictionary, 'a');
|
||||
result = _.indexBy<SampleObject>(numericDictionary, 'a', any);
|
||||
result = _.indexBy<{a: number}, SampleObject>(numericDictionary, {a: 42});
|
||||
result = _.indexBy<SampleObject>(numericDictionary, {a: 42});
|
||||
|
||||
result = _.indexBy<SampleObject>(dictionary);
|
||||
result = _.indexBy<SampleObject>(dictionary, dictionaryIterator);
|
||||
result = _.indexBy<SampleObject>(dictionary, dictionaryIterator, any);
|
||||
result = _.indexBy<SampleObject>(dictionary, 'a');
|
||||
result = _.indexBy<SampleObject>(dictionary, 'a', any);
|
||||
result = _.indexBy<{a: number}, SampleObject>(dictionary, {a: 42});
|
||||
result = _.indexBy<SampleObject>(dictionary, {a: 42});
|
||||
}
|
||||
|
||||
{
|
||||
let result: _.LoDashImplicitObjectWrapper<_.Dictionary<string>>;
|
||||
|
||||
result = _('abcd').indexBy();
|
||||
result = _('abcd').indexBy(stringIterator);
|
||||
result = _('abcd').indexBy(stringIterator, any);
|
||||
}
|
||||
|
||||
{
|
||||
let result: _.LoDashImplicitObjectWrapper<_.Dictionary<SampleObject>>;
|
||||
|
||||
result = _(array).indexBy();
|
||||
result = _(array).indexBy(listIterator);
|
||||
result = _(array).indexBy(listIterator, any);
|
||||
result = _(array).indexBy('a');
|
||||
result = _(array).indexBy('a', any);
|
||||
result = _(array).indexBy<{a: number}>({a: 42});
|
||||
|
||||
result = _(list).indexBy<SampleObject>();
|
||||
result = _(list).indexBy<SampleObject>(listIterator);
|
||||
result = _(list).indexBy<SampleObject>(listIterator, any);
|
||||
result = _(list).indexBy<SampleObject>('a');
|
||||
result = _(list).indexBy<SampleObject>('a', any);
|
||||
result = _(list).indexBy<{a: number}, SampleObject>({a: 42});
|
||||
result = _(list).indexBy<SampleObject>({a: 42});
|
||||
|
||||
result = _(numericDictionary).indexBy<SampleObject>();
|
||||
result = _(numericDictionary).indexBy<SampleObject>(numericDictionaryIterator);
|
||||
result = _(numericDictionary).indexBy<SampleObject>(numericDictionaryIterator, any);
|
||||
result = _(numericDictionary).indexBy<SampleObject>('a');
|
||||
result = _(numericDictionary).indexBy<SampleObject>('a', any);
|
||||
result = _(numericDictionary).indexBy<{a: number}, SampleObject>({a: 42});
|
||||
result = _(numericDictionary).indexBy<SampleObject>({a: 42});
|
||||
|
||||
result = _(dictionary).indexBy<SampleObject>();
|
||||
result = _(dictionary).indexBy<SampleObject>(dictionaryIterator);
|
||||
result = _(dictionary).indexBy<SampleObject>(dictionaryIterator, any);
|
||||
result = _(dictionary).indexBy<SampleObject>('a');
|
||||
result = _(dictionary).indexBy<SampleObject>('a', any);
|
||||
result = _(dictionary).indexBy<{a: number}, SampleObject>({a: 42});
|
||||
result = _(dictionary).indexBy<SampleObject>({a: 42});
|
||||
}
|
||||
|
||||
{
|
||||
let result: _.LoDashExplicitObjectWrapper<_.Dictionary<string>>;
|
||||
|
||||
result = _('abcd').chain().indexBy();
|
||||
result = _('abcd').chain().indexBy(stringIterator);
|
||||
result = _('abcd').chain().indexBy(stringIterator, any);
|
||||
}
|
||||
|
||||
{
|
||||
let result: _.LoDashExplicitObjectWrapper<_.Dictionary<SampleObject>>;
|
||||
|
||||
result = _(array).chain().indexBy();
|
||||
result = _(array).chain().indexBy(listIterator);
|
||||
result = _(array).chain().indexBy(listIterator, any);
|
||||
result = _(array).chain().indexBy('a');
|
||||
result = _(array).chain().indexBy('a', any);
|
||||
result = _(array).chain().indexBy<{a: number}>({a: 42});
|
||||
|
||||
result = _(list).chain().indexBy<SampleObject>();
|
||||
result = _(list).chain().indexBy<SampleObject>(listIterator);
|
||||
result = _(list).chain().indexBy<SampleObject>(listIterator, any);
|
||||
result = _(list).chain().indexBy<SampleObject>('a');
|
||||
result = _(list).chain().indexBy<SampleObject>('a', any);
|
||||
result = _(list).chain().indexBy<{a: number}, SampleObject>({a: 42});
|
||||
result = _(list).chain().indexBy<SampleObject>({a: 42});
|
||||
|
||||
result = _(numericDictionary).chain().indexBy<SampleObject>();
|
||||
result = _(numericDictionary).chain().indexBy<SampleObject>(numericDictionaryIterator);
|
||||
result = _(numericDictionary).chain().indexBy<SampleObject>(numericDictionaryIterator, any);
|
||||
result = _(numericDictionary).chain().indexBy<SampleObject>('a');
|
||||
result = _(numericDictionary).chain().indexBy<SampleObject>('a', any);
|
||||
result = _(numericDictionary).chain().indexBy<{a: number}, SampleObject>({a: 42});
|
||||
result = _(numericDictionary).chain().indexBy<SampleObject>({a: 42});
|
||||
|
||||
result = _(dictionary).chain().indexBy<SampleObject>();
|
||||
result = _(dictionary).chain().indexBy<SampleObject>(dictionaryIterator);
|
||||
result = _(dictionary).chain().indexBy<SampleObject>(dictionaryIterator, any);
|
||||
result = _(dictionary).chain().indexBy<SampleObject>('a');
|
||||
result = _(dictionary).chain().indexBy<SampleObject>('a', any);
|
||||
result = _(dictionary).chain().indexBy<{a: number}, SampleObject>({a: 42});
|
||||
result = _(dictionary).chain().indexBy<SampleObject>({a: 42});
|
||||
}
|
||||
}
|
||||
|
||||
result = <number[][]>_.invoke([[5, 1, 7], [3, 2, 1]], 'sort');
|
||||
result = <string[][]>_.invoke([123, 456], String.prototype.split, '');
|
||||
|
||||
Vendored
+195
-53
@@ -6710,65 +6710,207 @@ declare module _ {
|
||||
//_.indexBy
|
||||
interface LoDashStatic {
|
||||
/**
|
||||
* Creates an object composed of keys generated from the results of running each element
|
||||
* of the collection through the given callback. The corresponding value of each key is
|
||||
* the last element responsible for generating the key. The callback is bound to thisArg
|
||||
* and invoked with three arguments; (value, index|key, collection).
|
||||
*
|
||||
* If a property name is provided for callback the created "_.pluck" style callback will
|
||||
* return the property value of the given element.
|
||||
*
|
||||
* If an object is provided for callback the created "_.where" style callback will return
|
||||
* true for elements that have the properties of the given object, else false.
|
||||
* @param collection The collection to iterate over.
|
||||
* @param callback The function called per iteration.
|
||||
* @param thisArg The this binding of callback.
|
||||
* @return Returns the composed aggregate object.
|
||||
**/
|
||||
indexBy<T>(
|
||||
list: Array<T>,
|
||||
iterator: ListIterator<T, any>,
|
||||
context?: any): Dictionary<T>;
|
||||
|
||||
/**
|
||||
* @see _.indexBy
|
||||
**/
|
||||
indexBy<T>(
|
||||
list: List<T>,
|
||||
iterator: ListIterator<T, any>,
|
||||
context?: any): Dictionary<T>;
|
||||
|
||||
/**
|
||||
* @see _.indexBy
|
||||
* @param pluckValue _.pluck style callback
|
||||
**/
|
||||
indexBy<T>(
|
||||
collection: Array<T>,
|
||||
pluckValue: string): Dictionary<T>;
|
||||
|
||||
/**
|
||||
* @see _.indexBy
|
||||
* @param pluckValue _.pluck style callback
|
||||
**/
|
||||
* Creates an object composed of keys generated from the results of running each element of collection through
|
||||
* iteratee. The corresponding value of each key is the last element responsible for generating the key. The
|
||||
* iteratee function is bound to thisArg and invoked with three arguments:
|
||||
* (value, index|key, collection).
|
||||
*
|
||||
* If a property name is provided for iteratee the created _.property style callback returns the property
|
||||
* value of the given element.
|
||||
*
|
||||
* If a value is also provided for thisArg the created _.matchesProperty style callback returns true for
|
||||
* elements that have a matching property value, else false.
|
||||
*
|
||||
* If an object is provided for iteratee the created _.matches style callback returns true for elements that
|
||||
* have the properties of the given object, else false.
|
||||
*
|
||||
* @param collection The collection to iterate over.
|
||||
* @param iteratee The function invoked per iteration.
|
||||
* @param thisArg The this binding of iteratee.
|
||||
* @return Returns the composed aggregate object.
|
||||
*/
|
||||
indexBy<T>(
|
||||
collection: List<T>,
|
||||
pluckValue: string): Dictionary<T>;
|
||||
iteratee?: ListIterator<T, any>,
|
||||
thisArg?: any
|
||||
): Dictionary<T>;
|
||||
|
||||
/**
|
||||
* @see _.indexBy
|
||||
* @param whereValue _.where style callback
|
||||
**/
|
||||
indexBy<W, T>(
|
||||
collection: Array<T>,
|
||||
whereValue: W): Dictionary<T>;
|
||||
* @see _.indexBy
|
||||
*/
|
||||
indexBy<T>(
|
||||
collection: NumericDictionary<T>,
|
||||
iteratee?: NumericDictionaryIterator<T, any>,
|
||||
thisArg?: any
|
||||
): Dictionary<T>;
|
||||
|
||||
/**
|
||||
* @see _.indexBy
|
||||
* @param whereValue _.where style callback
|
||||
**/
|
||||
indexBy<W, T>(
|
||||
collection: List<T>,
|
||||
whereValue: W): Dictionary<T>;
|
||||
* @see _.indexBy
|
||||
*/
|
||||
indexBy<T>(
|
||||
collection: Dictionary<T>,
|
||||
iteratee?: DictionaryIterator<T, any>,
|
||||
thisArg?: any
|
||||
): Dictionary<T>;
|
||||
|
||||
/**
|
||||
* @see _.indexBy
|
||||
*/
|
||||
indexBy<T>(
|
||||
collection: List<T>|NumericDictionary<T>|Dictionary<T>,
|
||||
iteratee?: string,
|
||||
thisArg?: any
|
||||
): Dictionary<T>;
|
||||
|
||||
/**
|
||||
* @see _.indexBy
|
||||
*/
|
||||
indexBy<W extends Object, T>(
|
||||
collection: List<T>|NumericDictionary<T>|Dictionary<T>,
|
||||
iteratee?: W
|
||||
): Dictionary<T>;
|
||||
|
||||
/**
|
||||
* @see _.indexBy
|
||||
*/
|
||||
indexBy<T>(
|
||||
collection: List<T>|NumericDictionary<T>|Dictionary<T>,
|
||||
iteratee?: Object
|
||||
): Dictionary<T>;
|
||||
}
|
||||
|
||||
interface LoDashImplicitWrapper<T> {
|
||||
/**
|
||||
* @see _.indexBy
|
||||
*/
|
||||
indexBy(
|
||||
iteratee?: ListIterator<T, any>,
|
||||
thisArg?: any
|
||||
): LoDashImplicitObjectWrapper<Dictionary<T>>;
|
||||
}
|
||||
|
||||
interface LoDashImplicitArrayWrapper<T> {
|
||||
/**
|
||||
* @see _.indexBy
|
||||
*/
|
||||
indexBy(
|
||||
iteratee?: ListIterator<T, any>,
|
||||
thisArg?: any
|
||||
): LoDashImplicitObjectWrapper<Dictionary<T>>;
|
||||
|
||||
/**
|
||||
* @see _.indexBy
|
||||
*/
|
||||
indexBy(
|
||||
iteratee?: string,
|
||||
thisArg?: any
|
||||
): LoDashImplicitObjectWrapper<Dictionary<T>>;
|
||||
|
||||
/**
|
||||
* @see _.indexBy
|
||||
*/
|
||||
indexBy<W extends Object>(
|
||||
iteratee?: W
|
||||
): LoDashImplicitObjectWrapper<Dictionary<T>>;
|
||||
}
|
||||
|
||||
interface LoDashImplicitObjectWrapper<T> {
|
||||
/**
|
||||
* @see _.indexBy
|
||||
*/
|
||||
indexBy<T>(
|
||||
iteratee?: ListIterator<T, any>|NumericDictionaryIterator<T, any>|DictionaryIterator<T, any>,
|
||||
thisArg?: any
|
||||
): LoDashImplicitObjectWrapper<Dictionary<T>>;
|
||||
|
||||
/**
|
||||
* @see _.indexBy
|
||||
*/
|
||||
indexBy<T>(
|
||||
iteratee?: string,
|
||||
thisArg?: any
|
||||
): LoDashImplicitObjectWrapper<Dictionary<T>>;
|
||||
|
||||
/**
|
||||
* @see _.indexBy
|
||||
*/
|
||||
indexBy<W extends Object, T>(
|
||||
iteratee?: W
|
||||
): LoDashImplicitObjectWrapper<Dictionary<T>>;
|
||||
|
||||
/**
|
||||
* @see _.indexBy
|
||||
*/
|
||||
indexBy<T>(
|
||||
iteratee?: Object
|
||||
): LoDashImplicitObjectWrapper<Dictionary<T>>;
|
||||
}
|
||||
|
||||
interface LoDashExplicitWrapper<T> {
|
||||
/**
|
||||
* @see _.indexBy
|
||||
*/
|
||||
indexBy(
|
||||
iteratee?: ListIterator<T, any>,
|
||||
thisArg?: any
|
||||
): LoDashExplicitObjectWrapper<Dictionary<T>>;
|
||||
}
|
||||
|
||||
interface LoDashExplicitArrayWrapper<T> {
|
||||
/**
|
||||
* @see _.indexBy
|
||||
*/
|
||||
indexBy(
|
||||
iteratee?: ListIterator<T, any>,
|
||||
thisArg?: any
|
||||
): LoDashExplicitObjectWrapper<Dictionary<T>>;
|
||||
|
||||
/**
|
||||
* @see _.indexBy
|
||||
*/
|
||||
indexBy(
|
||||
iteratee?: string,
|
||||
thisArg?: any
|
||||
): LoDashExplicitObjectWrapper<Dictionary<T>>;
|
||||
|
||||
/**
|
||||
* @see _.indexBy
|
||||
*/
|
||||
indexBy<W extends Object>(
|
||||
iteratee?: W
|
||||
): LoDashExplicitObjectWrapper<Dictionary<T>>;
|
||||
}
|
||||
|
||||
interface LoDashExplicitObjectWrapper<T> {
|
||||
/**
|
||||
* @see _.indexBy
|
||||
*/
|
||||
indexBy<T>(
|
||||
iteratee?: ListIterator<T, any>|NumericDictionaryIterator<T, any>|DictionaryIterator<T, any>,
|
||||
thisArg?: any
|
||||
): LoDashExplicitObjectWrapper<Dictionary<T>>;
|
||||
|
||||
/**
|
||||
* @see _.indexBy
|
||||
*/
|
||||
indexBy<T>(
|
||||
iteratee?: string,
|
||||
thisArg?: any
|
||||
): LoDashExplicitObjectWrapper<Dictionary<T>>;
|
||||
|
||||
/**
|
||||
* @see _.indexBy
|
||||
*/
|
||||
indexBy<W extends Object, T>(
|
||||
iteratee?: W
|
||||
): LoDashExplicitObjectWrapper<Dictionary<T>>;
|
||||
|
||||
/**
|
||||
* @see _.indexBy
|
||||
*/
|
||||
indexBy<T>(
|
||||
iteratee?: Object
|
||||
): LoDashExplicitObjectWrapper<Dictionary<T>>;
|
||||
}
|
||||
|
||||
//_.invoke
|
||||
|
||||
Reference in New Issue
Block a user