最近写稍微复杂点的组件,发现 TS 的知识储备不够用,很多复杂的类型不好定义,花费了太多时间在 ts 上。比如
export type Field = | IFieldText | IFieldSingleSelecttype IFieldText = { type: 'text'}type IFieldSingleSelect = { type: 'single_select' // 选项 options: ISelectOption[]}
此时我想定义一个表单,表单的 key 为 Field 联合类型中可能存在的 key ,此时会报 options 不存在
type form:Field = { type: "", options: "" }
还有表单的数据类型根据 field.type 进行变化等等这种稍微复杂点的就抓耳挠腮,augment 写的也不好
有没有更方便解决这种问题的办法