In my current setup, I have :
const useFormTransform = <T>(
formValues: T,
transform: Partial<Record<keyof T, (value: T[keyof T]) => any>>,
) => ...
This is how it's used :
type Line = { id?: string; fromQuantity: number };
const line: Line = { id: 'abc', fromQuantity: 123 };
useFormTransform(
line,
{
id: f => f,
fromQuantity: f => transformNumber(Number(f)),
},
);
I am aiming for something like
Record<keyof T as U, (value: U) => any>
in the transform
argument so that the value
is strictly a number
, not string | undefined | number
as it currently is, since typeof line['fromQuantity'] === 'number'
I have tried various approaches but haven't been successful yet.
Appreciate any help! :)