Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

The type of setFieldValue seems incorrect. #3807

Closed
NagaiKoki opened this issue May 29, 2023 · 4 comments
Closed

The type of setFieldValue seems incorrect. #3807

NagaiKoki opened this issue May 29, 2023 · 4 comments

Comments

@NagaiKoki
Copy link
Contributor

Bug report

The following Eslint error appeared in the setFieldValue function when updating to version 2.3.2 of formik.

Avoid referencing unbound methods which may cause unintentional scoping of `this`.
If your function does not access `this`, you can annotate it with `this: void`, or consider using an arrow function instead.eslint@typescript-eslint/ unbound-method

When I look at the FormikHelpers types, though, they were defined as follows,

setFieldValue(field: string, value: any, shouldValidate?: boolean): Promise<void | FormikErrors<Values>>;.

However, looking at the implementation, I think the correct type is

setFieldValue: (field: string, value: any, shouldValidate?: boolean) => Promise<void | FormikErrors<Values>>;

Is this type correct?

Current Behavior

スクリーンショット 2023-05-29 14 32 11

export interface FormikHelpers<Values> {
    // ...
    setFieldValue(field: string, value: any, shouldValidate?: boolean): Promise<void | FormikErrors<Values>>;
     // ...
}

Expected behavior

export interface FormikHelpers<Values> {
    // ...
    setFieldValue: (field: string, value: any, shouldValidate?: boolean) => Promise<void | FormikErrors<Values>>;
  // ...
}

Reproducible example

Suggested solution(s)

Additional context

Your environment

Software Version(s)
Formik 2.4.0
React 18.2.0
TypeScript 5.0.0
Browser
npm/Yarn yarn
Operating System
@quantizor
Copy link
Collaborator

We can fix this, but it's probably also better to not check types that aren't yours with https://www.typescriptlang.org/tsconfig#skipLibCheck

@klarstrup
Copy link

I face this issue with skipLibCheck enabled.

@quantizor
Copy link
Collaborator

Fixed in https://github.com/jaredpalmer/formik/releases/tag/formik%402.4.1, thanks for contributing!

@NagaiKoki
Copy link
Contributor Author

@probablyup Thank you!

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

3 participants