Skip to content

PathValue returns never for bracket notation array paths like items[0].name #5111

@zalment

Description

@zalment

What happened?

When using defineField or any typed path API with bracket notation for array access (e.g., items[0].name), the PathValue type incorrectly resolves to never instead of the actual type.

The path is correctly accepted as valid (autocomplete works), but the return type is wrong.

Expected:

const [name] = defineField('items[0].name'); // name should be Ref<string>

Actual:

const [name] = defineField('items[0].name'); // name is Ref<never>

This happens because PathValue in types/paths.ts doesn't handle the key[index] pattern (e.g., items[0]) - it only handles dot notation (items.0).

Reproduction steps

  1. Create a form with a typed array field:
interface MyForm {
  items: { name: string }[];
}
const { defineField } = useForm<MyForm>();
  1. Use defineField with bracket notation:
const [itemName] = defineField('items[0].name');
  1. Hover over itemName - it shows Ref<never> instead of Ref<string>

  2. The same issue occurs with items[0] (should be { name: string }, but returns never)

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

Code of Conduct

Additional context

I've identified the root cause in packages/vee-validate/src/types/paths.ts - the PathValue type doesn't parse the key[index] bracket notation pattern. I have a fix ready and would be happy to submit a PR if this issue is confirmed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions