|
1 | | -import { expect } from 'tstyche'; |
| 1 | +import type { GetFieldType } from 'lodash'; |
| 2 | +import { expect, test } from 'tstyche'; |
2 | 3 |
|
3 | 4 | import { type ValueAtPathT } from '../../../src/utils'; |
4 | 5 |
|
@@ -63,3 +64,21 @@ expect(y1).type.toBeNever(); |
63 | 64 |
|
64 | 65 | declare const y2: ValueAtPathT<unknown, null, never>; |
65 | 66 | expect(y2).type.toBeNever(); |
| 67 | + |
| 68 | +// Test related to: https://github.com/birdofpreyru/react-global-state/issues/89 |
| 69 | +test('type resolution with [] brackets in path', () => { |
| 70 | + type TA = Record<string, string | undefined>; |
| 71 | + type StateT = { a: Record<string, TA | undefined> }; |
| 72 | + |
| 73 | + expect<GetFieldType<StateT, `a.${string}.${string}`>>() |
| 74 | + .type.toEqual<string | undefined>(); |
| 75 | + |
| 76 | + expect<GetFieldType<StateT, `a[${string}][${string}]`>>() |
| 77 | + .type.toEqual<string | undefined>(); |
| 78 | + |
| 79 | + expect<ValueAtPathT<StateT, `a.${string}.${string}`, never>>() |
| 80 | + .type.toEqual<string | undefined>(); |
| 81 | + |
| 82 | + expect<ValueAtPathT<StateT, `a[${string}][${string}]`, never>>() |
| 83 | + .type.toEqual<string | undefined>(); |
| 84 | +}); |
0 commit comments