Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Eliminate the use of object in TypeScript #415

Open
virzak opened this issue May 2, 2021 · 0 comments
Open

Eliminate the use of object in TypeScript #415

virzak opened this issue May 2, 2021 · 0 comments

Comments

@virzak
Copy link

virzak commented May 2, 2021

What is the current behavior?

The object type in the line

allValues: object,

Breaks the rule
https://github.com/typescript-eslint/typescript-eslint/blob/v4.22.0/packages/eslint-plugin/docs/rules/ban-types.md

This error occurs outside the library code when implementing the field-level-validation example in TypeScript:

const composeValidators = (...validators: FieldValidator<string>[]) => (value: string, allValues: object) =>
  validators.reduce((error, validator) => error || validator(value, allValues), undefined);

I think this can be fixed with

-type FieldValidator<FieldValue> = (
+type FieldValidator<FieldValue, FormValues> = (
   value: FieldValue,
-  allValues: object,
+  allValues: FormValues,
   meta?: FieldState<FieldValue>
 ) => any | Promise<any>
-type GetFieldValidator<FieldValue> = () =>
-  | FieldValidator<FieldValue>
+type GetFieldValidator<FieldValue, FormValues> = () =>
+  | FieldValidator<FieldValue, FormValues>
   | undefined

and a few propagating changes including react-final-form.

What are your thoughts on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant