Skip to content

Could this form example snippet be improved? #5383

@troix1

Description

@troix1

Package

v4.x

Description

Hi! I was going through the NuxtUI form docs and noticed that in FormExampleBasic.vue, the validate function currently uses the any type.

It might be more accurate to use Partial<Schema> instead, which would provide better type safety and align with the form’s schema typing.

const validate = (state: any): FormError[] => {
  const errors = []
  if (!state.email) errors.push({ name: 'email', message: 'Required' })
  if (!state.password) errors.push({ name: 'password', message: 'Required' })
  return errors
}

replace any with Partial<Schema>

const validate = (state: Partial<Schema>): FormError[] => {
  const errors = []
  if (!state.email) errors.push({ name: 'email', message: 'Required' })
  if (!state.password) errors.push({ name: 'password', message: 'Required' })
  return errors
}

Link to docs: https://ui.nuxt.com/docs/components/form

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requestedv4#4488

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions