interface RequiredAttributes { id: string; name: string; required: boolean; disabled: boolean;} interface WidgetCommonProps<V, A> { config: Config; value: V | undefined; attributes: A & RequiredAttributes; errors: ValidationError<unknown>[];} interface SelectWidgetProps<V> extends WidgetCommonProps<V, HTMLSelectAttributes> { multiple: boolean; options: EnumOption<SchemaValue>[];} interface RadioWidgetProps<V> extends WidgetCommonProps<V, HTMLInputAttributes> { options: EnumOption<SchemaValue>[];} interface FileWidgetProps<V> extends WidgetCommonProps<V, HTMLInputAttributes> { multiple: boolean; loading: boolean; processing: boolean;} interface WidgetsAndProps<V> { text: WidgetCommonProps<V, HTMLInputAttributes>; textarea: WidgetCommonProps<V, HTMLTextareaAttributes>; number: WidgetCommonProps<V, HTMLInputAttributes>; select: SelectWidgetProps<V>; radio: RadioWidgetProps<V>; checkbox: WidgetCommonProps<V, HTMLInputAttributes>; checkboxes: RadioWidgetProps<V>; file: FileWidgetProps<V>;}
You can change the widget type if they have compatible types.
interface WidgetValue { text: string; textarea: string; number: number | null; select: SchemaValue; radio: SchemaValue; checkbox: boolean; checkboxes: SchemaArrayValue; file: FileList;} type WidgetType = keyof WidgetsAndProps<SchemaValue>; type CompatibleWidgetType<T extends WidgetType> = { [W in WidgetType]: WidgetValue[T] extends WidgetValue[W] ? W : never;}[WidgetType];