What is the current way of defining the ref for an innerRef attribute using TypeScript?

Question

Currently the innerRef has signature of (instance: any) => void which does not fit any type I can remind of, like FormikProps or FormikHelpers

Before that when I was using the 1.5 version where I could call methods like setFieldTouched on the ref therefore an inner Ref should be of type FormikHelper or at least inherit it. The (instance: any) => void looks broken

1 possible answer(s) on “What is the current way of defining the ref for an innerRef attribute using TypeScript?

  1. Since TypeScript is not really helpful i used as casting.

    <Formik innerRef={instance=>{formikRef=instance}} {…otherProps}/>`

    This however makes a non-constant formikRef variable

    let formikRef = useRef(null) as any;

    I do not think this is correct way with 2.x