In the code below:
interface MyInterface {
a: {
b: {
c: "c";
};
};
}
type ParentProps = keyof MyInterface
type ChildProps<ParentProp extends ParentProps> = keyof MyInterface[ParentProp]
type GrandChildType<ParentProp extends ParentProps, ChildProp extends ChildProps<ParentProp>> =
MyInterface[ParentProp][ChildProp]['c']
I'm getting an error in the GrandChildType saying:
Type '"c"' cannot be used to index type 'MyInterface[ParentProp][ChildProp]'.(2536)
However, if I change the last line to:
type GrandChildType<ParentProp extends ParentProps, ChildProp extends ChildProps<ParentProp>> =
MyInterface[ParentProp][ChildProp]
type test = GrandChildType<'a', 'b'>['c']
then I properly get the type of c which is "c". So, the question is: why can't I get that value type when using Generics if both ParentProps and ChildProps are keys extracted from MyInterface?
reproducible link: typescript playground