【发布时间】:2021-01-03 16:05:56
【问题描述】:
很难解释我想要达到的目标(不确定是否可能)所以这里是代码:
interface CellConfig {
btn?: cellBtn;
...
}
interface CellBtn {
isEnabled?: boolean;
label?: string;
style?: any;
classes?: any;
}
interface DataSet {
position: number;
name: string;
weight: string;
symbol: string;
config?: *missing part, not sure how to do it*
}
所以我想要这样的东西:
let dataSet: DataSet = {
position: 1,
name: 'test',
weight: '11',
symbol: '123',
config: { position: { btn: {isEnabled: true }}, name: { btn: { isEnabled: true }}}
}
基本上,config 应该是可选对象,并且只允许使用 DataSet 键(config 除外),并且 config 对象中的每个键都应该是 CellConfig 类型
【问题讨论】:
-
这个问题好像和generics没什么关系。
标签: javascript typescript typescript-typings typescript-generics