arrayFlatUnnecessaryDepths
Reports using
1as the depth argument of.flat()since it is the default.
✅ This rule is included in the tsstylisticandstylisticStrictpresets.
The default depth for Array.prototype.flat() is 1, so passing it explicitly is redundant.
This rule reports when 1 is passed as the depth argument to .flat().
Examples
Section titled “Examples”declare const const array: number[][]
array: number[][];const array: number[][]
array.Array<number[]>.flat<number[][], 1>(this: number[][], depth?: 1 | undefined): number[]
Returns a new array with all sub-array elements concatenated into it recursively up to the
specified depth.
flat(1);declare const const array: number[][] | undefined
array: number[][] | undefined;const array: number[][] | undefined
array?.Array<number[]>.flat<A, D>(this: A, depth?: D | undefined): FlatArray<A, D>[]
Returns a new array with all sub-array elements concatenated into it recursively up to the
specified depth.
flat(1);declare const const array: number[][]
array: number[][];const array: number[][]
array.Array<number[]>.flat<number[][], 1>(this: number[][], depth?: 1 | undefined): number[]
Returns a new array with all sub-array elements concatenated into it recursively up to the
specified depth.
flat();declare const const array: number[][][]
array: number[][][];const array: number[][][]
array.Array<number[][]>.flat<number[][][], 2>(this: number[][][], depth?: 2 | undefined): number[]
Returns a new array with all sub-array elements concatenated into it recursively up to the
specified depth.
flat(2);declare const const array: number[]
array: number[];const array: number[]
array.Array<number>.flat<number[], number>(this: number[], depth?: number | undefined): number[]
Returns a new array with all sub-array elements concatenated into it recursively up to the
specified depth.
flat(var Infinity: number
Infinity);Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If you prefer to be explicit about the depth argument for readability or consistency, you may disable this rule.