@@ -45,6 +45,16 @@ describe('unit-d:types/At', () => {
45
45
expectTypeOf < TestSubject < [ 'a' ] , never , F > > ( ) . toEqualTypeOf < F > ( )
46
46
} )
47
47
48
+ it ( 'should equal Fallback<T[K], F> if IsKey<T, K> extends true' , ( ) => {
49
+ // Arrange
50
+ type T = { '0' : 'a' ; 1 : 'b' } & [ Vehicle ]
51
+ type K = '0' | '1' | 0 | 1
52
+ type Expect = Fallback < T [ K ] , F >
53
+
54
+ // Expect
55
+ expectTypeOf < TestSubject < T , K , F > > ( ) . toEqualTypeOf < Expect > ( )
56
+ } )
57
+
48
58
it ( 'should equal Fallback<T[number], F> if K is any' , ( ) => {
49
59
// Arrange
50
60
type T = [ 'a' , 'b' , 'c' ?]
@@ -143,7 +153,7 @@ describe('unit-d:types/At', () => {
143
153
} )
144
154
} )
145
155
146
- describe ( 'number extends Length <T>' , ( ) => {
156
+ describe ( 'number extends Indices <T>' , ( ) => {
147
157
type T = Vehicle [ ]
148
158
149
159
it ( 'should equal F if K is never' , ( ) => {
@@ -160,11 +170,21 @@ describe('unit-d:types/At', () => {
160
170
expectTypeOf < TestSubject < T , Integer , F > > ( ) . toEqualTypeOf < Expect > ( )
161
171
expectTypeOf < TestSubject < T , any , F > > ( ) . toEqualTypeOf < Expect > ( )
162
172
} )
173
+
174
+ it ( 'should equal Fallback<T[K], F> if IsKey<T, K> extends true' , ( ) => {
175
+ // Arrange
176
+ type T = Vehicle [ ] & { '0' : 'a' ; 1 : 'b' }
177
+ type K = '0' | '1' | 0 | 1
178
+ type Expect = Fallback < T [ K ] , F >
179
+
180
+ // Expect
181
+ expectTypeOf < TestSubject < T , K , F > > ( ) . toEqualTypeOf < Expect > ( )
182
+ } )
163
183
} )
164
184
} )
165
185
166
186
describe ( 'T extends string' , ( ) => {
167
- describe ( 'IsLiteral<Length<T> > extends true' , ( ) => {
187
+ describe ( 'IsLiteral<T > extends true' , ( ) => {
168
188
type Splitter < T extends string > = Split < T , EmptyString >
169
189
170
190
it ( 'should equal Splitter<T>[number] if K is any' , ( ) => {
@@ -269,7 +289,7 @@ describe('unit-d:types/At', () => {
269
289
} )
270
290
} )
271
291
272
- describe ( 'number extends Length <T>' , ( ) => {
292
+ describe ( 'number extends Indices <T>' , ( ) => {
273
293
type T = string
274
294
275
295
it ( 'should equal F if K is never' , ( ) => {
@@ -286,6 +306,16 @@ describe('unit-d:types/At', () => {
286
306
expectTypeOf < TestSubject < T , Integer , F > > ( ) . toEqualTypeOf < Expect > ( )
287
307
expectTypeOf < TestSubject < T , any , F > > ( ) . toEqualTypeOf < Expect > ( )
288
308
} )
309
+
310
+ it ( 'should equal Fallback<T[K], F> if IsKey<T, K> extends true' , ( ) => {
311
+ // Arrange
312
+ type T = string & { '0' : 'a' ; 1 : 'b' }
313
+ type K = '0' | '1' | 0 | 1
314
+ type Expect = Fallback < T [ K ] , F >
315
+
316
+ // Expect
317
+ expectTypeOf < TestSubject < T , K , F > > ( ) . toEqualTypeOf < Expect > ( )
318
+ } )
289
319
} )
290
320
} )
291
321
0 commit comments