I'm struggling to create parameters that rely on the type of field being transmitted. It's puzzling why the handler includes any type of arguments.
type TInputType = 'text' | 'number' | 'date';
type THandler<V> = (e: Event, data: { value: V }) => void
type TProps<T extends TInputType = TInputType> = {
type: T
} & (
T extends 'number' ? {
value: number
handler: THandler<number>
} : {
value: number
handler: THandler<string>
}
)
function input(props: TProps) {
console.log(props);
}
const val = 1234;
input({ type: 'number', value: val, handler: (e, { value }) => {
----------------------------------------------^----^--------------
Parameter 'e' implicitly has an 'any' type.(7006)
Binding element 'value' implicitly has an 'any' type.(7031)
------------------------------------------------------------------
console.log(e, value)
} });
Looking for guidance. Any help would be appreciated!