import { DOMEvent } from "@/helpers"; type UpdatingEvent = "onBlur" | "onChange" | "onInput"; type FormFieldHelperOptions = { event: UpdatingEvent, property: string, } export function formFieldProps(subject: T, update: (value: T) => void, options: Partial> = {}) { const { event = "onChange", property = "value", } = options; return

( field: P, extractor: (...args: TArgs) => T[P] = ((event: DOMEvent) => event.target.value as unknown as T[P]) as any ): any => ({ [property]: subject[field], [event]: (...args: TArgs) => update({ ...subject, [field]: extractor(...args), } as T) }) } export type BoundProperty = { [property in TProperty]: T; } & { [event in TEvent]: (value: T) => void; }