Skip to content

Commit a06062a

Browse files
committed
refactor(utils): [get] improve top-level property support
- allow retrieval of dot-keyed properties (e.g. serve.port) - allow retrieval of symbol-keyed properties Signed-off-by: Lexus Drumgold <[email protected]>
1 parent 728a6a2 commit a06062a

22 files changed

+730
-642
lines changed

src/types/__tests__/at.spec-d.ts

+33-3
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ describe('unit-d:types/At', () => {
4545
expectTypeOf<TestSubject<['a'], never, F>>().toEqualTypeOf<F>()
4646
})
4747

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+
4858
it('should equal Fallback<T[number], F> if K is any', () => {
4959
// Arrange
5060
type T = ['a', 'b', 'c'?]
@@ -143,7 +153,7 @@ describe('unit-d:types/At', () => {
143153
})
144154
})
145155

146-
describe('number extends Length<T>', () => {
156+
describe('number extends Indices<T>', () => {
147157
type T = Vehicle[]
148158

149159
it('should equal F if K is never', () => {
@@ -160,11 +170,21 @@ describe('unit-d:types/At', () => {
160170
expectTypeOf<TestSubject<T, Integer, F>>().toEqualTypeOf<Expect>()
161171
expectTypeOf<TestSubject<T, any, F>>().toEqualTypeOf<Expect>()
162172
})
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+
})
163183
})
164184
})
165185

166186
describe('T extends string', () => {
167-
describe('IsLiteral<Length<T>> extends true', () => {
187+
describe('IsLiteral<T> extends true', () => {
168188
type Splitter<T extends string> = Split<T, EmptyString>
169189

170190
it('should equal Splitter<T>[number] if K is any', () => {
@@ -269,7 +289,7 @@ describe('unit-d:types/At', () => {
269289
})
270290
})
271291

272-
describe('number extends Length<T>', () => {
292+
describe('number extends Indices<T>', () => {
273293
type T = string
274294

275295
it('should equal F if K is never', () => {
@@ -286,6 +306,16 @@ describe('unit-d:types/At', () => {
286306
expectTypeOf<TestSubject<T, Integer, F>>().toEqualTypeOf<Expect>()
287307
expectTypeOf<TestSubject<T, any, F>>().toEqualTypeOf<Expect>()
288308
})
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+
})
289319
})
290320
})
291321

0 commit comments

Comments
 (0)