Hi Folks. probably Yawar =)
Hit a thing today doing bindings for an external function that seemed incorrect to me.
the type signature in ts has a few type [parameters] and shows an optional options argument:
export type UseFormRegister<TFieldValues extends FieldValues> = <
TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
>(
name: TFieldName,
options?: RegisterOptions<TFieldValues, TFieldName>,
) => UseFormRegisterReturn;
The function implementation in js provides a default empty object for options:
const register: UseFormRegister = (name, options = {}) => {
my signature in rescript asserts the presence of options to avoid adding runtime code there but allow options.
type useFormRegister<
'tFieldValues, //extends FieldValues
'tFieldName, // extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
'event
> =
(
'tFieldName, // name:
// options typed as undefined in ts but easy to make an empty options which has
// same effect as default options = {}
// and saves Undefined.return calls everywhere - AxM
registerOptions<value, 'event, 'tFieldValues, 'tFieldName>, // options:
) => useFormRegisterReturn;
This causes my function to be invoked with Curry._2.
Inside of Curry._2 it evaluates register.length and gets 1.
Then calls register with one arg, returning the intended useFormRegisterReturn, and then applying once more with the options which breaks since useFormRegister is not a function.
f.apply is not a function
I have worked around by making register an uncurried function but it seems that no external function is safe from this trouble? Any ideas?
Thanks!
Alex