1
+ type Flatten < T > = T extends readonly ( infer U ) [ ] ? U : T ;
2
+
1
3
interface ReadonlyArray < T > {
2
4
3
5
/**
@@ -11,105 +13,81 @@ interface ReadonlyArray<T> {
11
13
* thisArg is omitted, undefined is used as the this value.
12
14
*/
13
15
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 ,
15
17
thisArg ?: This
16
- ) : U [ ]
17
-
18
+ ) : Flatten < U > [ ]
18
19
19
20
/**
20
21
* Returns a new array with all sub-array elements concatenated into it recursively up to the
21
22
* specified depth.
22
23
*
23
24
* @param depth The maximum recursion depth
24
25
*/
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 ] > > > > > > > [ ] ;
47
27
48
28
/**
49
29
* Returns a new array with all sub-array elements concatenated into it recursively up to the
50
30
* specified depth.
51
31
*
52
32
* @param depth The maximum recursion depth
53
33
*/
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 ] > > > > > > [ ] ;
60
35
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 ] > > > > > [ ] ;
67
43
68
44
/**
69
45
* Returns a new array with all sub-array elements concatenated into it recursively up to the
70
46
* specified depth.
71
47
*
72
48
* @param depth The maximum recursion depth
73
49
*/
74
- flat < U > ( this :
75
- ReadonlyArray < U [ ] [ ] > |
50
+ flat < U extends readonly any [ ] > ( this : U , depth : 4 ) : Flatten < Flatten < Flatten < Flatten < U [ number ] > > > > [ ] ;
76
51
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 ] > > > [ ] ;
79
59
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 ] > > [ ] ;
82
67
83
68
/**
84
69
* Returns a new array with all sub-array elements concatenated into it recursively up to the
85
70
* specified depth.
86
71
*
87
72
* @param depth The maximum recursion depth
88
73
*/
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 ] > [ ] ;
94
75
95
76
/**
96
77
* Returns a new array with all sub-array elements concatenated into it recursively up to the
97
78
* specified depth.
98
79
*
99
80
* @param depth The maximum recursion depth
100
81
*/
101
- flat < U > ( this :
102
- ReadonlyArray < U > ,
103
- depth : 0
104
- ) : U [ ] ;
82
+ flat < U extends readonly any [ ] > ( this : U , depth : 0 ) : U [ number ] [ ] ;
105
83
106
84
/**
107
85
* Returns a new array with all sub-array elements concatenated into it recursively up to the
108
86
* specified depth. If no depth is provided, flat method defaults to the depth of 1.
109
87
*
110
88
* @param depth The maximum recursion depth
111
89
*/
112
- flat < U > ( depth ? : number ) : any [ ] ;
90
+ flat ( this : readonly any [ ] , depth : number ) : any [ ] ;
113
91
}
114
92
115
93
interface Array < T > {
@@ -125,79 +103,79 @@ interface Array<T> {
125
103
* thisArg is omitted, undefined is used as the this value.
126
104
*/
127
105
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 ,
129
107
thisArg ?: This
130
- ) : U [ ]
108
+ ) : Flatten < U > [ ]
131
109
132
110
/**
133
111
* Returns a new array with all sub-array elements concatenated into it recursively up to the
134
112
* specified depth.
135
113
*
136
114
* @param depth The maximum recursion depth
137
115
*/
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 ] > > > > > > > [ ] ;
139
117
140
118
/**
141
119
* Returns a new array with all sub-array elements concatenated into it recursively up to the
142
120
* specified depth.
143
121
*
144
122
* @param depth The maximum recursion depth
145
123
*/
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 ] > > > > > > [ ] ;
147
125
148
126
/**
149
127
* Returns a new array with all sub-array elements concatenated into it recursively up to the
150
128
* specified depth.
151
129
*
152
130
* @param depth The maximum recursion depth
153
131
*/
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 ] > > > > > [ ] ;
155
133
156
134
/**
157
135
* Returns a new array with all sub-array elements concatenated into it recursively up to the
158
136
* specified depth.
159
137
*
160
138
* @param depth The maximum recursion depth
161
139
*/
162
- flat < U > ( this : U [ ] [ ] [ ] [ ] [ ] , depth : 4 ) : U [ ] ;
140
+ flat < U extends readonly any [ ] > ( this : U , depth : 4 ) : Flatten < Flatten < Flatten < Flatten < U [ number ] > > > > [ ] ;
163
141
164
142
/**
165
143
* Returns a new array with all sub-array elements concatenated into it recursively up to the
166
144
* specified depth.
167
145
*
168
146
* @param depth The maximum recursion depth
169
147
*/
170
- flat < U > ( this : U [ ] [ ] [ ] [ ] , depth : 3 ) : U [ ] ;
148
+ flat < U extends readonly any [ ] > ( this : U , depth : 3 ) : Flatten < Flatten < Flatten < U [ number ] > > > [ ] ;
171
149
172
150
/**
173
151
* Returns a new array with all sub-array elements concatenated into it recursively up to the
174
152
* specified depth.
175
153
*
176
154
* @param depth The maximum recursion depth
177
155
*/
178
- flat < U > ( this : U [ ] [ ] [ ] , depth : 2 ) : U [ ] ;
156
+ flat < U extends readonly any [ ] > ( this : U , depth : 2 ) : Flatten < Flatten < U [ number ] > > [ ] ;
179
157
180
158
/**
181
159
* Returns a new array with all sub-array elements concatenated into it recursively up to the
182
160
* specified depth.
183
161
*
184
162
* @param depth The maximum recursion depth
185
163
*/
186
- flat < U > ( this : U [ ] [ ] , depth ?: 1 ) : U [ ] ;
164
+ flat < U extends readonly any [ ] > ( this : U , depth ?: 1 ) : Flatten < U [ number ] > [ ] ;
187
165
188
166
/**
189
167
* Returns a new array with all sub-array elements concatenated into it recursively up to the
190
168
* specified depth.
191
169
*
192
170
* @param depth The maximum recursion depth
193
171
*/
194
- flat < U > ( this : U [ ] , depth : 0 ) : U [ ] ;
172
+ flat < U extends readonly any [ ] > ( this : U , depth : 0 ) : U [ number ] [ ] ;
195
173
196
174
/**
197
175
* Returns a new array with all sub-array elements concatenated into it recursively up to the
198
176
* specified depth. If no depth is provided, flat method defaults to the depth of 1.
199
177
*
200
178
* @param depth The maximum recursion depth
201
179
*/
202
- flat < U > ( depth ? : number ) : any [ ] ;
180
+ flat ( this : readonly any [ ] , depth : number ) : any [ ] ;
203
181
}
0 commit comments