如何从嵌套对象/组件树推导最终对象类型
TypeScript表单结构类型推导问题
原始表单结构
const myForm = { widget: "col", children: [ { widget: 'row', children: [ { widget: 'text', prop: 'name' }, { widget: 'number', prop: 'age' } ] }, { widget: 'text', prop: 'location', optional: true } ] } as const type MyForm = Infer<typeof myForm>
期望推导结果
希望通过Infer类型得到以下对象结构:
{ name: string age: number location?: string }
当前状态
已实现遍历对象树并推导每个widget对应的类型,但在将这些零散类型整合为最终的完整对象类型环节遇到阻碍。当前鼠标悬停在MyForm类型上可查看已完成的进展。
内容的提问来源于stack exchange,提问作者Andrei
相关产品推荐
相关产品推荐

