Given the following data:
const tree = {
_size: 0,
a: {
_size: 0,
b: {
_size: 0,
}
},
c: {
_size: 0
}
}
Is there a way to make it so that TypeScript understands that every key that is not _size
is of type Dir
?
I would like to create a type that includes itself recursively. So far, I've got the following:
type Dir = {
_size: number,
[key: string]: /* Dir? */
}
Where I would like to comment out the "Dir" in order for it to recursively include itself. However, this is giving me the following error:
Property '_size' of type 'number' is not assignable to 'string' index type 'string'