A typed handler no longer fits a bare FormProps
Detect
- In your code: a props object or a wrapper component typed as bare
FormPropsthat takes typed handlers, such ascustomValidate: (formData: MyData | undefined, …)oronSubmit: (e: IChangeEvent<MyData>) => …. - The type checker reports
Type '…' is not assignable to type '…'.(TS2322) on that handler.
Change
Values annotated without a type argument still fit a typed form, but the reverse does not hold: FormProps means FormProps<unknown>, and a handler typed for MyData doesn't fit it. Give FormProps your data type:
-function MyForm(props: FormProps) {
+function MyForm(props: FormProps<MyData>) {
return <Form {...props} />;
}
Verify
- The type checker accepts the typed handlers on the props object or wrapper.
- Nothing changes at runtime.
Also read: