I have an Object with unknown length where each item can either have a true/false value or another Object with true/false values. The structure is limited to just two dimensions.
const items: SOMETYPE = {
a: true,
b: {
ba: true,
bc: false,
bd: true,
},
c: false,
// etc...
}
Should I define this object using an interface with [] brackets, or the same thing but as a type? Which option is more common and standard when checking this kind of object?
I could also use Record inside Record for this purpose.
All approaches work, but which one is considered the most "correct" or best practice? Is there a better way?
interface ItemsInterface {
[name: string]: boolean | { [name: string]: boolean }
}
type ItemsType = {
[name: string]: boolean | { [name: string]: boolean }
}
type ItemsTypeRecord = Record<string, boolean | Record<string, boolean>>