As I understand, TS prefers direct type usages over "boxed" ones (e.g. in function) to infer a generic type from.
type Props<O, V> = {
options: O[]
getOptionValue: (o: O) => V
value?: V
onChange?: (v: V, o: O) => void
}
In this snippet type V
is inferred from value
field which is undesirable since value
property is optional. Can I somehow force generic type inference to rely on getOptionValue
property?
Sandbox example where if no value
passed to a component its onChange
argument v
becomes unknown