diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index e0f2b8226..cd84de417 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -239,10 +239,13 @@ result = _([1, 2, 3]).take(function (num) { result = _(foodsOrganic).take('organic').value(); result = _(foodsType).take({ 'type': 'fruit' }).value(); -result = _.flatten([1, [2], [3, [[4]]]]); -result = _.flatten([1, [2], [3, [[4]]]], true); -var result: any -result = _.flatten(stoogesQuotes, 'quotes'); +result = >_.flatten([[1, 2], [3, 4]]); +result = >_.flatten([[1, 2], [3, 4], 5, 6]); +result = >>>_.flatten([1, [2], [3, [[4]]]]); + +result = >_.flatten([1, [2], [[3]]], true); +result = >_.flatten([1, [2], [3, [[4]]]], true); +result = >_.flatten([1, [2], [3, [[false]]]], true); result = <_.LoDashArrayWrapper>_([1, [2], [3, [[4]]]]).flatten(); result = <_.LoDashArrayWrapper>_([1, [2], [3, [[4]]]]).flatten(true); diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index a906b907f..8c265cb8f 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -769,123 +769,28 @@ declare module _ { take(whereValue: W): LoDashArrayWrapper; } + interface MaybeNestedList extends List> { } + interface RecursiveList extends List> { } + //_.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(array: Array, isShallow?: boolean): T[]; + * Flattens a nested array. + * + * @param array The array to flatten. + * @return `array` flattened. + **/ + flatten(array: MaybeNestedList): T[]; /** - * @see _.flatten - **/ - flatten(array: List, isShallow?: boolean): T[]; - - /** - * @see _.flatten - **/ - flatten( - array: Array, - isShallow: boolean, - callback: ListIterator, - thisArg?: any): T[]; - - /** - * @see _.flatten - **/ - flatten( - array: List, - isShallow: boolean, - callback: ListIterator, - thisArg?: any): T[]; - - /** - * @see _.flatten - **/ - flatten( - array: Array, - callback: ListIterator, - thisArg?: any): T[]; - - /** - * @see _.flatten - **/ - flatten( - array: List, - callback: ListIterator, - thisArg?: any): T[]; - - /** - * @see _.flatten - **/ - flatten( - array: Array, - isShallow: boolean, - whereValue: W): T[]; - - /** - * @see _.flatten - **/ - flatten( - array: List, - isShallow: boolean, - whereValue: W): T[]; - - /** - * @see _.flatten - **/ - flatten( - array: Array, - whereValue: W): T[]; - - /** - * @see _.flatten - **/ - flatten( - array: List, - whereValue: W): T[]; - - /** - * @see _.flatten - **/ - flatten( - array: Array, - isShallow: boolean, - pluckValue: string): T[]; - - /** - * @see _.flatten - **/ - flatten( - array: List, - isShallow: boolean, - pluckValue: string): T[]; - - /** - * @see _.flatten - **/ - flatten( - array: Array, - pluckValue: string): T[]; - - /** - * @see _.flatten - **/ - flatten( - array: List, - 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(array: RecursiveList, isDeep: boolean): T[]; } interface LoDashArrayWrapper {