1+ type Flatten < T > = T extends readonly ( infer U ) [ ] ? U : T ;
2+
13interface ReadonlyArray < T > {
24
35 /**
@@ -11,105 +13,81 @@ interface ReadonlyArray<T> {
1113 * thisArg is omitted, undefined is used as the this value.
1214 */
1315 flatMap < U , This = undefined > (
14- callback : ( this : This , value : T , index : number , array : T [ ] ) => U | ReadonlyArray < U > ,
16+ callback : ( this : This , value : T , index : number , array : T [ ] ) => U ,
1517 thisArg ?: This
16- ) : U [ ]
17-
18+ ) : Flatten < U > [ ]
1819
1920 /**
2021 * Returns a new array with all sub-array elements concatenated into it recursively up to the
2122 * specified depth.
2223 *
2324 * @param depth The maximum recursion depth
2425 */
25- flat < U > ( this :
26- ReadonlyArray < U [ ] [ ] [ ] [ ] > |
27-
28- ReadonlyArray < ReadonlyArray < U [ ] [ ] [ ] > > |
29- ReadonlyArray < ReadonlyArray < U [ ] [ ] > [ ] > |
30- ReadonlyArray < ReadonlyArray < U [ ] > [ ] [ ] > |
31- ReadonlyArray < ReadonlyArray < U > [ ] [ ] [ ] > |
32-
33- ReadonlyArray < ReadonlyArray < ReadonlyArray < U [ ] [ ] > > > |
34- ReadonlyArray < ReadonlyArray < ReadonlyArray < U > [ ] [ ] > > |
35- ReadonlyArray < ReadonlyArray < ReadonlyArray < U > > [ ] [ ] > |
36- ReadonlyArray < ReadonlyArray < ReadonlyArray < U > [ ] > [ ] > |
37- ReadonlyArray < ReadonlyArray < ReadonlyArray < U [ ] > > [ ] > |
38- ReadonlyArray < ReadonlyArray < ReadonlyArray < U [ ] > [ ] > > |
39-
40- ReadonlyArray < ReadonlyArray < ReadonlyArray < ReadonlyArray < U [ ] > > > > |
41- ReadonlyArray < ReadonlyArray < ReadonlyArray < ReadonlyArray < U > [ ] > > > |
42- ReadonlyArray < ReadonlyArray < ReadonlyArray < ReadonlyArray < U > > [ ] > > |
43- ReadonlyArray < ReadonlyArray < ReadonlyArray < ReadonlyArray < U > > > [ ] > |
44-
45- ReadonlyArray < ReadonlyArray < ReadonlyArray < ReadonlyArray < ReadonlyArray < U > > > > > ,
46- depth : 4 ) : U [ ] ;
26+ flat < U extends readonly any [ ] > ( this : U , depth : 7 ) : Flatten < Flatten < Flatten < Flatten < Flatten < Flatten < Flatten < U [ number ] > > > > > > > [ ] ;
4727
4828 /**
4929 * Returns a new array with all sub-array elements concatenated into it recursively up to the
5030 * specified depth.
5131 *
5232 * @param depth The maximum recursion depth
5333 */
54- flat < U > ( this :
55- ReadonlyArray < U [ ] [ ] [ ] > |
56-
57- ReadonlyArray < ReadonlyArray < U > [ ] [ ] > |
58- ReadonlyArray < ReadonlyArray < U [ ] > [ ] > |
59- ReadonlyArray < ReadonlyArray < U [ ] [ ] > > |
34+ flat < U extends readonly any [ ] > ( this : U , depth : 6 ) : Flatten < Flatten < Flatten < Flatten < Flatten < Flatten < U [ number ] > > > > > > [ ] ;
6035
61- ReadonlyArray < ReadonlyArray < ReadonlyArray < U [ ] > > > |
62- ReadonlyArray < ReadonlyArray < ReadonlyArray < U > [ ] > > |
63- ReadonlyArray < ReadonlyArray < ReadonlyArray < U > > [ ] > |
64-
65- ReadonlyArray < ReadonlyArray < ReadonlyArray < ReadonlyArray < U > > > > ,
66- depth : 3 ) : U [ ] ;
36+ /**
37+ * Returns a new array with all sub-array elements concatenated into it recursively up to the
38+ * specified depth.
39+ *
40+ * @param depth The maximum recursion depth
41+ */
42+ flat < U extends readonly any [ ] > ( this : U , depth : 5 ) : Flatten < Flatten < Flatten < Flatten < Flatten < U [ number ] > > > > > [ ] ;
6743
6844 /**
6945 * Returns a new array with all sub-array elements concatenated into it recursively up to the
7046 * specified depth.
7147 *
7248 * @param depth The maximum recursion depth
7349 */
74- flat < U > ( this :
75- ReadonlyArray < U [ ] [ ] > |
50+ flat < U extends readonly any [ ] > ( this : U , depth : 4 ) : Flatten < Flatten < Flatten < Flatten < U [ number ] > > > > [ ] ;
7651
77- ReadonlyArray < ReadonlyArray < U [ ] > > |
78- ReadonlyArray < ReadonlyArray < U > [ ] > |
52+ /**
53+ * Returns a new array with all sub-array elements concatenated into it recursively up to the
54+ * specified depth.
55+ *
56+ * @param depth The maximum recursion depth
57+ */
58+ flat < U extends readonly any [ ] > ( this : U , depth : 3 ) : Flatten < Flatten < Flatten < U [ number ] > > > [ ] ;
7959
80- ReadonlyArray < ReadonlyArray < ReadonlyArray < U > > > ,
81- depth : 2 ) : U [ ] ;
60+ /**
61+ * Returns a new array with all sub-array elements concatenated into it recursively up to the
62+ * specified depth.
63+ *
64+ * @param depth The maximum recursion depth
65+ */
66+ flat < U extends readonly any [ ] > ( this : U , depth : 2 ) : Flatten < Flatten < U [ number ] > > [ ] ;
8267
8368 /**
8469 * Returns a new array with all sub-array elements concatenated into it recursively up to the
8570 * specified depth.
8671 *
8772 * @param depth The maximum recursion depth
8873 */
89- flat < U > ( this :
90- ReadonlyArray < U [ ] > |
91- ReadonlyArray < ReadonlyArray < U > > ,
92- depth ?: 1
93- ) : U [ ] ;
74+ flat < U extends readonly any [ ] > ( this : U , depth ?: 1 ) : Flatten < U [ number ] > [ ] ;
9475
9576 /**
9677 * Returns a new array with all sub-array elements concatenated into it recursively up to the
9778 * specified depth.
9879 *
9980 * @param depth The maximum recursion depth
10081 */
101- flat < U > ( this :
102- ReadonlyArray < U > ,
103- depth : 0
104- ) : U [ ] ;
82+ flat < U extends readonly any [ ] > ( this : U , depth : 0 ) : U [ number ] [ ] ;
10583
10684 /**
10785 * Returns a new array with all sub-array elements concatenated into it recursively up to the
10886 * specified depth. If no depth is provided, flat method defaults to the depth of 1.
10987 *
11088 * @param depth The maximum recursion depth
11189 */
112- flat < U > ( depth ? : number ) : any [ ] ;
90+ flat ( this : readonly any [ ] , depth : number ) : any [ ] ;
11391}
11492
11593interface Array < T > {
@@ -125,79 +103,79 @@ interface Array<T> {
125103 * thisArg is omitted, undefined is used as the this value.
126104 */
127105 flatMap < U , This = undefined > (
128- callback : ( this : This , value : T , index : number , array : T [ ] ) => U | ReadonlyArray < U > ,
106+ callback : ( this : This , value : T , index : number , array : T [ ] ) => U ,
129107 thisArg ?: This
130- ) : U [ ]
108+ ) : Flatten < U > [ ]
131109
132110 /**
133111 * Returns a new array with all sub-array elements concatenated into it recursively up to the
134112 * specified depth.
135113 *
136114 * @param depth The maximum recursion depth
137115 */
138- flat < U > ( this : U [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] , depth : 7 ) : U [ ] ;
116+ flat < U extends readonly any [ ] > ( this : U , depth : 7 ) : Flatten < Flatten < Flatten < Flatten < Flatten < Flatten < Flatten < U [ number ] > > > > > > > [ ] ;
139117
140118 /**
141119 * Returns a new array with all sub-array elements concatenated into it recursively up to the
142120 * specified depth.
143121 *
144122 * @param depth The maximum recursion depth
145123 */
146- flat < U > ( this : U [ ] [ ] [ ] [ ] [ ] [ ] [ ] , depth : 6 ) : U [ ] ;
124+ flat < U extends readonly any [ ] > ( this : U , depth : 6 ) : Flatten < Flatten < Flatten < Flatten < Flatten < Flatten < U [ number ] > > > > > > [ ] ;
147125
148126 /**
149127 * Returns a new array with all sub-array elements concatenated into it recursively up to the
150128 * specified depth.
151129 *
152130 * @param depth The maximum recursion depth
153131 */
154- flat < U > ( this : U [ ] [ ] [ ] [ ] [ ] [ ] , depth : 5 ) : U [ ] ;
132+ flat < U extends readonly any [ ] > ( this : U , depth : 5 ) : Flatten < Flatten < Flatten < Flatten < Flatten < U [ number ] > > > > > [ ] ;
155133
156134 /**
157135 * Returns a new array with all sub-array elements concatenated into it recursively up to the
158136 * specified depth.
159137 *
160138 * @param depth The maximum recursion depth
161139 */
162- flat < U > ( this : U [ ] [ ] [ ] [ ] [ ] , depth : 4 ) : U [ ] ;
140+ flat < U extends readonly any [ ] > ( this : U , depth : 4 ) : Flatten < Flatten < Flatten < Flatten < U [ number ] > > > > [ ] ;
163141
164142 /**
165143 * Returns a new array with all sub-array elements concatenated into it recursively up to the
166144 * specified depth.
167145 *
168146 * @param depth The maximum recursion depth
169147 */
170- flat < U > ( this : U [ ] [ ] [ ] [ ] , depth : 3 ) : U [ ] ;
148+ flat < U extends readonly any [ ] > ( this : U , depth : 3 ) : Flatten < Flatten < Flatten < U [ number ] > > > [ ] ;
171149
172150 /**
173151 * Returns a new array with all sub-array elements concatenated into it recursively up to the
174152 * specified depth.
175153 *
176154 * @param depth The maximum recursion depth
177155 */
178- flat < U > ( this : U [ ] [ ] [ ] , depth : 2 ) : U [ ] ;
156+ flat < U extends readonly any [ ] > ( this : U , depth : 2 ) : Flatten < Flatten < U [ number ] > > [ ] ;
179157
180158 /**
181159 * Returns a new array with all sub-array elements concatenated into it recursively up to the
182160 * specified depth.
183161 *
184162 * @param depth The maximum recursion depth
185163 */
186- flat < U > ( this : U [ ] [ ] , depth ?: 1 ) : U [ ] ;
164+ flat < U extends readonly any [ ] > ( this : U , depth ?: 1 ) : Flatten < U [ number ] > [ ] ;
187165
188166 /**
189167 * Returns a new array with all sub-array elements concatenated into it recursively up to the
190168 * specified depth.
191169 *
192170 * @param depth The maximum recursion depth
193171 */
194- flat < U > ( this : U [ ] , depth : 0 ) : U [ ] ;
172+ flat < U extends readonly any [ ] > ( this : U , depth : 0 ) : U [ number ] [ ] ;
195173
196174 /**
197175 * Returns a new array with all sub-array elements concatenated into it recursively up to the
198176 * specified depth. If no depth is provided, flat method defaults to the depth of 1.
199177 *
200178 * @param depth The maximum recursion depth
201179 */
202- flat < U > ( depth ? : number ) : any [ ] ;
180+ flat ( this : readonly any [ ] , depth : number ) : any [ ] ;
203181}
0 commit comments