diff --git a/src/array-types.ts b/src/array-types.ts index 4d7dae8..5ecd280 100644 --- a/src/array-types.ts +++ b/src/array-types.ts @@ -259,3 +259,15 @@ type ZipImplementation = T extends [infer It * type Zip2 = Zip<[1, 2, 3], ["a", "b"]>; */ export type Zip = ZipImplementation; + +/** + * Returns the flatten type of an array. + * + * @example + * // Expected: number + * type Flatten1 = FlattenArrayType; + * + * // Expected: string + * type Flatten2 = FlattenArrayType; + */ +export type FlattenArrayType = Array extends (infer Type)[] ? FlattenArrayType : Array; diff --git a/test/array-types.test.ts b/test/array-types.test.ts index 99d60cf..33559a0 100644 --- a/test/array-types.test.ts +++ b/test/array-types.test.ts @@ -136,3 +136,13 @@ describe("Zip", () => { >(); }); }); + +describe("FlattenArrayType", () => { + test("Flatten an array type", () => { + expectTypeOf>().toEqualTypeOf(); + expectTypeOf>().toEqualTypeOf(); + expectTypeOf>().toEqualTypeOf(); + expectTypeOf>().toEqualTypeOf(); + expectTypeOf>().toEqualTypeOf(); + }); +});