我正在努力为具有如下嵌套结构的对象定义类型:
const nestedDictionary = {
a: {
b: true
},
c: true,
d: {
e: {
f: true
}
}
}
type Dictionary = {
[x: string]: boolean | Dictionary;
};
const nestedDictionary: Dictionary;
或者,如果您更喜欢使用类型作为参数:
type GenericDictionary<T> = {
[x: string]: T | GenericDictionary<T>;
};
const nestedDictionary: GenericDictionary<boolean>;
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句