Is there a way to dynamically type an object field based on the value of its sibling?
In this scenario, I have a layout type that resolves into a cell type. Cells can have a layout which should be based on the type of the field.
export interface Layout<T> {
cells: (Layout<T> | AutoCellProps<T>)[];
}
export type AutoCellProps<T, F extends keyof T = keyof T> = AutoArrayProps<T, F>;
export interface AutoArrayProps<T, Field extends keyof T> {
dataType: 'Array';
name: Field;
layout: Layout<T[Field]>;
}
type formData = {
section1: {field1: string},
section2: {field2: string},
}
const layout: Layout<formData> = {
cells: [
{
dataType: 'Array',
name: 'section1',
layout: <--- want this to be
// Layout<{
// field1: string;
// } >
},
{
dataType: 'Array',
name: 'section2',
layout: <--- want this to be
// Layout<{
// field2: string;
// } >
}
]
}