Skip to content

Commit 81e78b8

Browse files
committed
Add regression test
1 parent d7691e3 commit 81e78b8

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

tests/cases/conformance/types/literal/templateLiteralTypes1.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,3 +215,25 @@ type AA<T extends number, Q extends number> =
215215
[true, true] extends [IsNegative<T>, IsNegative<Q>] ? 'Every thing is ok!' : ['strange', IsNegative<T>, IsNegative<Q>];
216216

217217
type BB = AA<-2, -2>;
218+
219+
// Repro from #40970
220+
221+
type PathKeys<T> =
222+
T extends readonly any[] ? Extract<keyof T, `${number}`> | SubKeys<T, Extract<keyof T, `${number}`>> :
223+
T extends object ? Extract<keyof T, string> | SubKeys<T, Extract<keyof T, string>> :
224+
never;
225+
226+
type SubKeys<T, K extends string> = K extends keyof T ? `${K}.${PathKeys<T[K]>}` : never;
227+
228+
declare function getProp2<T, P extends PathKeys<T>>(obj: T, path: P): PropType<T, P>;
229+
230+
const obj2 = {
231+
name: 'John',
232+
age: 42,
233+
cars: [
234+
{ make: 'Ford', age: 10 },
235+
{ make: 'Trabant', age: 35 }
236+
]
237+
} as const;
238+
239+
let make = getProp2(obj2, 'cars.1.make'); // 'Trabant'

0 commit comments

Comments
 (0)