- Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue
Milestone
Description
TypeScript Version: 4.1.0-dev
Code
typePathKeys<T>=Textendsreadonlyany[] ? Extract<keyofT, `${number}`>|SubKeys<T,Extract<keyofT, `${number}`>> : Textendsobject ? Extract<keyofT,string>|SubKeys<T,Extract<keyofT,string>> : never;typeSubKeys<T,Kextendsstring>=KextendskeyofT ? `${K}.${PathKeys<T[K]>}` : never;typePropType<T,Pathextendsstring>=PathextendskeyofT ? T[Path] : Pathextends `${infer K}.${infer R}` ? KextendskeyofT ? PropType<T[K],R> : unknown : unknown;declarefunctiongetProp<T,PextendsPathKeys<T>>(obj: T,path: P): PropType<T,P>;constobj={name: 'John',age: 42,cars: [{make: 'Ford',age: 10},{make: 'Trabant',age: 35}]}asconst;letmake=getProp(obj,'cars.1.make');// 'Trabant'Expected behavior:
No errors.
Actual behavior:
"Type instantiation is excessively deep and possibly infinite" error on declaration of getProp.
Playground Link:
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue