Merge pull request #4791 from pimterry/lodash-flatten

Fix the very broken lodash flatten() type definitions
This commit is contained in:
Masahiro Wakame
2015-07-15 01:44:34 +09:00
2 changed files with 31 additions and 158 deletions

View File

@@ -239,14 +239,18 @@ result = <number[]>_([1, 2, 3]).take(function (num) {
result = <IFoodOrganic[]>_(foodsOrganic).take('organic').value();
result = <IFoodType[]>_(foodsType).take({ 'type': 'fruit' }).value();
result = <number[]>_.flatten([1, [2], [3, [[4]]]]);
result = <any[]>_.flatten([1, [2], [3, [[4]]]], true);
var result: any
result = <string[]>_.flatten(stoogesQuotes, 'quotes');
result = <Array<number>>_.flatten([[1, 2], [3, 4]]);
result = <Array<number>>_.flatten([[1, 2], [3, 4], 5, 6]);
result = <Array<number|Array<Array<number>>>>_.flatten([1, [2], [3, [[4]]]]);
result = <Array<number>>_.flatten([1, [2], [[3]]], true);
result = <Array<number>>_.flatten<number>([1, [2], [3, [[4]]]], true);
result = <Array<number|boolean>>_.flatten<number|boolean>([1, [2], [3, [[false]]]], true);
result = <_.LoDashArrayWrapper<number>>_([[1, 2], [3, 4], 5, 6]).flatten();
result = <_.LoDashArrayWrapper<number|Array<Array<number>>>>_([1, [2], [3, [[4]]]]).flatten();
result = <_.LoDashArrayWrapper<number>>_([1, [2], [3, [[4]]]]).flatten();
result = <_.LoDashArrayWrapper<number>>_([1, [2], [3, [[4]]]]).flatten(true);
result = <_.LoDashArrayWrapper<string>>_(stoogesQuotes).flatten('quotes');
result = <number>_.indexOf([1, 2, 3, 1, 2, 3], 2);
result = <number>_.indexOf([1, 2, 3, 1, 2, 3], 2, 3);

173
lodash/lodash.d.ts vendored
View File

@@ -769,171 +769,40 @@ declare module _ {
take<W>(whereValue: W): LoDashArrayWrapper<T>;
}
interface MaybeNestedList<T> extends List<T|List<T>> { }
interface RecursiveList<T> extends List<T|RecursiveList<T>> { }
//_.flatten
interface LoDashStatic {
/**
* Flattens a nested array (the nesting can be to any depth). If isShallow is truey, the
* array will only be flattened a single level. If a callback is provided each element of
* the array is passed through the callback before flattening. The callback is bound to
* thisArg and invoked with three arguments; (value, index, array).
*
* 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 array The array to flatten.
* @param shallow If true then only flatten one level, optional, default = false.
* @return `array` flattened.
**/
flatten<T>(array: Array<any>, isShallow?: boolean): T[];
* Flattens a nested array.
*
* @param array The array to flatten.
* @return `array` flattened.
**/
flatten<T>(array: MaybeNestedList<T>): T[];
/**
* @see _.flatten
**/
flatten<T>(array: List<any>, isShallow?: boolean): T[];
/**
* @see _.flatten
**/
flatten<T>(
array: Array<any>,
isShallow: boolean,
callback: ListIterator<any, T>,
thisArg?: any): T[];
/**
* @see _.flatten
**/
flatten<T>(
array: List<any>,
isShallow: boolean,
callback: ListIterator<any, T>,
thisArg?: any): T[];
/**
* @see _.flatten
**/
flatten<T>(
array: Array<any>,
callback: ListIterator<any, T>,
thisArg?: any): T[];
/**
* @see _.flatten
**/
flatten<T>(
array: List<any>,
callback: ListIterator<any, T>,
thisArg?: any): T[];
/**
* @see _.flatten
**/
flatten<W, T>(
array: Array<any>,
isShallow: boolean,
whereValue: W): T[];
/**
* @see _.flatten
**/
flatten<W, T>(
array: List<any>,
isShallow: boolean,
whereValue: W): T[];
/**
* @see _.flatten
**/
flatten<W, T>(
array: Array<any>,
whereValue: W): T[];
/**
* @see _.flatten
**/
flatten<W, T>(
array: List<any>,
whereValue: W): T[];
/**
* @see _.flatten
**/
flatten<T>(
array: Array<any>,
isShallow: boolean,
pluckValue: string): T[];
/**
* @see _.flatten
**/
flatten<T>(
array: List<any>,
isShallow: boolean,
pluckValue: string): T[];
/**
* @see _.flatten
**/
flatten<T>(
array: Array<any>,
pluckValue: string): T[];
/**
* @see _.flatten
**/
flatten<T>(
array: List<any>,
pluckValue: string): T[];
* Flattens a nested array. If isDeep is true the array is recursively flattened, otherwise it is only
* flattened a single level.
*
* @param array The array to flatten.
* @param deep Specify a deep flatten.
* @return `array` flattened.
**/
flatten<T>(array: RecursiveList<T>, isDeep: boolean): List<T> | RecursiveList<T>;
}
interface LoDashArrayWrapper<T> {
/**
* @see _.flatten
**/
flatten<Flat>(isShallow?: boolean): LoDashArrayWrapper<Flat>;
* @see _.flatten
**/
flatten<T>(): LoDashArrayWrapper<any>;
/**
* @see _.flatten
**/
flatten<Flat>(
isShallow: boolean,
callback: ListIterator<T, Flat>,
thisArg?: any): LoDashArrayWrapper<Flat>;
/**
* @see _.flatten
**/
flatten<Flat>(
callback: ListIterator<T, Flat>,
thisArg?: any): LoDashArrayWrapper<Flat>;
/**
* @see _.flatten
**/
flatten<Flat>(
isShallow: boolean,
pluckValue: string): LoDashArrayWrapper<Flat>;
/**
* @see _.flatten
**/
flatten<Flat>(
pluckValue: string): LoDashArrayWrapper<Flat>;
/**
* @see _.flatten
**/
flatten<Flat, W>(
isShallow: boolean,
whereValue: W): LoDashArrayWrapper<Flat>;
/**
* @see _.flatten
**/
flatten<Flat, W>(
whereValue: W): LoDashArrayWrapper<Flat>;
flatten<T>(isShallow: boolean): LoDashArrayWrapper<any>;
}
//_.indexOf