diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 3e3e7e101..b4ccdc2bb 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -412,14 +412,40 @@ result = >_.flatten([1, [2], [[3]]], true); result = >_.flatten([1, [2], [3, [[4]]]], true); result = >_.flatten([1, [2], [3, [[false]]]], true); -result = >_.flattenDeep([[[[1]]]]); - result = <_.LoDashArrayWrapper>_([[1, 2], [3, 4], 5, 6]).flatten(); result = <_.LoDashArrayWrapper>>>_([1, [2], [3, [[4]]]]).flatten(); result = <_.LoDashArrayWrapper>_([1, [2], [3, [[4]]]]).flatten(true); -result = <_.LoDashArrayWrapper>_([1, [2], [3, [[4]]]]).flattenDeep(); +// _.flattenDeep +module TestFlattenDeep { + interface RecursiveArray extends Array> {} + interface ListOfRecursiveArraysOrValues extends _.List> {} + interface RecursiveList extends _.List> { } + + let recursiveArray: RecursiveArray; + let listOfMaybeRecursiveArraysOrValues: ListOfRecursiveArraysOrValues; + let recursiveList: RecursiveList; + + { + let result: TResult[]; + + result = _.flattenDeep(recursiveArray); + result = _.flattenDeep(listOfMaybeRecursiveArraysOrValues); + + result = _(recursiveArray).flattenDeep().value(); + + result = _(listOfMaybeRecursiveArraysOrValues).flattenDeep().value(); + } + + { + let result: any; + + result = _.flattenDeep(recursiveList); + + result = _(recursiveList).flattenDeep().value(); + } +} // _.head module TestHead { diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 423c232fa..9c8b499c2 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -860,6 +860,8 @@ declare module _ { } interface MaybeNestedList extends List> { } + interface RecursiveArray extends Array> { } + interface ListOfRecursiveArraysOrValues extends List> { } interface RecursiveList extends List> { } //_.flatten @@ -886,16 +888,6 @@ declare module _ { * @return `array` flattened. **/ flatten(array: RecursiveList, isDeep: boolean): List | RecursiveList; - - /** - * Recursively flattens a nested array. - * - * _.flattenDeep(x) is equivalent to _.flatten(x, true); - * - * @param array The array to flatten - * @return `array` recursively flattened - */ - flattenDeep(array: RecursiveList): List } interface LoDashArrayWrapper { @@ -908,11 +900,41 @@ declare module _ { * @see _.flatten **/ flatten(isShallow: boolean): LoDashArrayWrapper; + } + + //_.flattenDeep + interface LoDashStatic { + /** + * Recursively flattens a nested array. + * + * @param array The array to recursively flatten. + * @return Returns the new flattened array. + */ + flattenDeep(array: RecursiveArray): T[]; /** * @see _.flattenDeep */ - flattenDeep(): LoDashArrayWrapper; + flattenDeep(array: ListOfRecursiveArraysOrValues): T[]; + + /** + * @see _.flattenDeep + */ + flattenDeep(array: RecursiveList): any[]; + } + + interface LoDashArrayWrapper { + /** + * @see _.flattenDeep + */ + flattenDeep(): LoDashArrayWrapper; + } + + interface LoDashObjectWrapper { + /** + * @see _.flattenDeep + */ + flattenDeep(): LoDashArrayWrapper; } //_.head