Skip to content

Typescript error on validation #97

Closed
@cinemaster

Description

@cinemaster

Are you submitting a bug report or a feature request?

bug report

What is the current behavior?

It's just error on typescripts.

Type '(value: UserValue[]) => ValidationErrors[]' is not assignable to type 'FieldValidator<UserValue>'.
  Types of parameters 'value' and 'value' are incompatible.
    Type 'UserValue' is missing the following properties from type 'UserValue[]': length, pop, push, concat, and 28 more.  TS2322

    221 |                     ...
    222 |                   />
  > 223 |                   <FieldArray<UserValue> name="users" validate={this.validateUser}>
        |                                                        ^
    224 |                     {({ fields }) => (
    225 |                       ...

and my validation is

validateUser = (value: UserValue[]) => {
	...
};

What is the expected behavior?

I think on definition UseFieldArrayConfig interface here, it should be assigned validate method as validate?: FieldValidator<FieldValue[]>.Otherwise it's defined with FieldValidator<FieldValue> and it occurs above type mismatch.

What's your environment?

% grep final-form ./package.json
./package.json:10:    "final-form": "^4.16.1",
./package.json:11:    "final-form-arrays": "^1.1.2",
./package.json:21:    "react-final-form": "^6.3.0",
./package.json:22:    "react-final-form-arrays": "^3.1.0",

Other information

If this change is ok, I can create PR for this.

Activity

erikras

erikras commented on Jul 12, 2019

@erikras
Member

Or maybe...

extends UseFieldConfig<FieldValue> ➡️ extends UseFieldConfig<FieldValue[]>

?

cinemaster

cinemaster commented on Jul 15, 2019

@cinemaster
ContributorAuthor

Ah, yes.
It's much better, I think.

MaciejSzewczyszyn

MaciejSzewczyszyn commented on Aug 20, 2019

@MaciejSzewczyszyn

Hi, any progress on this?

evgenii-bond

evgenii-bond commented on Sep 30, 2019

@evgenii-bond

any progress on this?

erikras

erikras commented on Jul 23, 2020

@erikras
Member

Published fix in v3.1.2.

locked as resolved and limited conversation to collaborators on May 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @MaciejSzewczyszyn@erikras@cinemaster@evgenii-bond

      Issue actions

        Typescript error on validation · Issue #97 · final-form/react-final-form-arrays