Skip to content

Types problem with different path syntax #4295

Closed
@bgoscinski

Description

@bgoscinski

What happened?

The path syntax that works with form errors generated by validation schemas is rejected by form.setFieldValue typechecking. This only affects TS usage because if I silence the TS error form.setFieldValue works as expected using both syntaxes.

  • steps[0].name works for getting errorMessage from field but is not accepted by form.setFieldValue
  • steps.0.name doesn't work for getting errorMessage from field, but is accepted by form.setFieldValue

Can the Path type be updated so that it produces paths like this:

type Step = {
  name: string
}

type Form = {
  steps: Step[]
}

type Result = Path<Form> // `steps` | `steps[${number}]` | `steps[${number}].name`
//                                          ^         ^          ^         ^

// instead of
type Result = Path<Form> // `steps` | `steps.${number}` | `steps.${number}.name`
//                                          ^                   ^         

Reproduction steps

  1. Visit https://stackblitz.com/edit/vee-validate-v4-cross-field-validation-rfx97g?file=src%2Fmain.ts
  2. See the TS error at line 39 of main.ts
  3. See the error message displayed only for steps[0].name in rendered app side

Version

Vue.js 3.x and vee-validate 4.x

What browsers are you seeing the problem on?

  • Firefox
  • Chrome
  • Safari
  • Microsoft Edge

Relevant log output

No response

Demo link

https://stackblitz.com/edit/vee-validate-v4-cross-field-validation-rfx97g?file=src%2Fmain.ts

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions