Trying to understand type inference and stumbling on this Formik example

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>

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 :thinking:

It’s probably a bug in editor extension

1 Like

Yes, might be a bug in the editor extension.
Playground shows the inferred type.

1 Like

Of course, thanks - that makes sense. I’ll create an issue for this at GitHub.

Edit, created the issue: Possible bug with type inference.