Reputation: 1273
I'm struggling to define a type for an object with a nested structure like this:
const nestedDictionary = {
a: {
b: true
},
c: true,
d: {
e: {
f: true
}
}
}
Upvotes: 1
Views: 3791
Reputation: 139
type Dictionary = {
[x: string]: boolean | Dictionary;
};
const nestedDictionary: Dictionary;
Or, if you prefer to use type as a parameter:
type GenericDictionary<T> = {
[x: string]: T | GenericDictionary<T>;
};
const nestedDictionary: GenericDictionary<boolean>;
Upvotes: 8