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

Form: values are not strongly typed #7338

Open
4 tasks
BenJackGill opened this issue Feb 26, 2025 · 1 comment
Open
4 tasks

Form: values are not strongly typed #7338

BenJackGill opened this issue Feb 26, 2025 · 1 comment
Labels
Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible

Comments

@BenJackGill
Copy link

Describe the bug

The TypeScript generic for the yupResolver does not provide strong typings for the form data.

I expected event.values.password to be strongly typed due to providing FormData to yupResolver<FormData>.

If that is not the purpose of the yupResolver generic, then how do we get strong typings?

<template>
  <Form
    @submit="handleSubmitPasswordReset"
    :resolver="validationResolver"
    :initalValues="initalValues"
    v-slot="$form"
  >
    <div class="flex flex-col gap-1">
      <FloatLabel variant="on">
        <VPassword
          id="password"
          name="password"
          toggle-mask
          @strength-rating="passwordStrengthRating = $event"
        />
        <VLabel required html-for="password">New Password</VLabel>
      </FloatLabel>
      <VFieldError v-if="$form.password?.invalid">
        {{ $form.password.error.message }}
      </VFieldError>
    </div>

    <Button
      :loading="isLoading"
      :disabled="!$form.password.value"
      label="Submit"
      type="submit"
      class="w-full"
    />
  </Form>
</template>

<script setup lang="ts">
import { Form } from '@primevue/forms';
import { yupResolver } from '@primevue/forms/resolvers/yup';

type FormData = {
  password: string | null;
};

const initalValues: FormData = {
  password: null,
};

const ValidationSchema = object({
  password: string().required('Password is required'),
});

const validationResolver = yupResolver<FormData>(ValidationSchema);

const handleSubmitPasswordReset = async (event: FormSubmitEvent) => {
  if (event.valid) {
    // This 'password' property has weak typing with an 'any' type
    // It should be 'string | null' because we have provided strong
    // typings using FormData. Would also be good if '$form.password'
    // was strongly typed in the template.
    console.log('Doing a password reset here...', event.values.password);
  }
};
</script>

Pull Request Link

No response

Reason for not contributing a PR

  • Lack of time
  • Unsure how to implement the fix/feature
  • Difficulty understanding the codebase
  • Other

Other Reason

No response

Reproducer

https://stackblitz.com/edit/ywanqa7v-vqn3w9ya?file=src%2FApp.vue

Environment

TypeScript, Vue 3, PrimeVue 4.3.1

Vue version

3.5.13

PrimeVue version

4.3.1

Node version

No response

Browser(s)

No response

Steps to reproduce the behavior

  1. Open the reproduction in a TypeScript environment. Not sure if the provided reproduction has TypeScript? I couldn't find a TypeScript PrimeVue StackBlitz to use.
  2. See that event.values.password is not strongly typed

Expected behavior

event.values.password should be strongly typed

@BenJackGill BenJackGill added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Feb 26, 2025
@xl495
Copy link
Contributor

xl495 commented Feb 27, 2025

Is this it? #7304

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible
Projects
None yet
Development

No branches or pull requests

2 participants