Sometimes I don’t quite understand when and why the compiler can infer the types vs when it can’t.
I am trying to create some simple bindings for Formik and one of them looks like this:
type formikInput<'a> = {initialValues: 'a, onSubmit: 'a => unit}
type formikOutput<'a> = {values: 'a}
type formikHook<'a> = formikInput<'a> => formikOutput<'a>
@module("formik")
external use: formikHook<'a> = "useFormik"
Then I use that binding in another file like so:
let initialValues = {
"name": "",
"description": "",
}
let onSubmit = values => Js.log(values)
let formik = Formik.use({
initialValues: initialValues,
onSubmit: onSubmit,
})
// Hovering over values gives me the expected type, but hovering over formik.values just gives me 'a
let values = formik.values
I’m wondering why the type of formik.values
is not inferred? But when I assign it the compiler picks the right type again