From a9c67da7192ea19daffea664a94dfbd19ef49d28 Mon Sep 17 00:00:00 2001 From: Robert Stocks Date: Fri, 27 Sep 2019 00:06:08 +0100 Subject: [PATCH] lodash: fix flattenDeep to correctly handle strings (#38625) * lodash: fix flattenDeep to correctly handle strings * fix whitespace --- types/lodash/ts3.1/common/array.d.ts | 4 +++- types/lodash/ts3.1/lodash-tests.ts | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/types/lodash/ts3.1/common/array.d.ts b/types/lodash/ts3.1/common/array.d.ts index 73e4e642c2..3831ba97ce 100644 --- a/types/lodash/ts3.1/common/array.d.ts +++ b/types/lodash/ts3.1/common/array.d.ts @@ -488,7 +488,9 @@ declare module "../index" { */ flatten(): T extends Many ? CollectionChain : CollectionChain; } - type Flat = (T extends List ? never : T); + + type Flat = T extends string ? T : (T extends List ? never : T); + interface LoDashStatic { /** * Recursively flattens a nested array. diff --git a/types/lodash/ts3.1/lodash-tests.ts b/types/lodash/ts3.1/lodash-tests.ts index 339f1f2c3e..927a8fae8c 100644 --- a/types/lodash/ts3.1/lodash-tests.ts +++ b/types/lodash/ts3.1/lodash-tests.ts @@ -497,6 +497,9 @@ _.chain([1, 2, 3, 4]).unshift(5, 6); // $ExpectType CollectionChain _.flattenDeep([1, [2, [3, [4, 5]]]]); // $ExpectType number[] _.flattenDeep({0: 1, 1: [2, [3, [4, 5]]], length: 2}); // $ExpectType number[] + _.flattenDeep(['x']); // $ExpectType string[] + _.flattenDeep(['x', ['y']]); // $ExpectType string[] + _.flattenDeep([1, 2, 3]); // $ExpectType number[] _.flattenDeep([[1, 2, 3]]); // $ExpectType number[] _.flattenDeep([1, [2, [3, [4, 5]]]]); // $ExpectType number[]