Can anybody explain to me what this error means?
I'm not looking for a solution but rather an understanding of the actual problem here.
const tree1 = {
val: 1,
left: null,
right: {
val: 2,
left: {
val: 3,
left: null,
right: null,
},
right: null,
},
} as const;
interface TreeNode {
val: number;
left: TreeNode | null;
right: TreeNode | null;
}
type InOrderTraversal<
T extends TreeNode | null
> = T extends null
? []
: [
...InOrderTraversal<T["left"]>, // --> Type '"left"' can't be used to index type 'T',
T["val"], // --> Type '"val"' can't be used to index type 'T',
...InOrderTraversal<T["right"]>. // --> Type '"right"' can't be used to index type 'T'
];
type A = InOrderTraversal<typeof tree1>; // [1, 3, 2]
Thanks!