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

Property 'message' does not exist on type 'DeepMap<String, FieldError>'. #2487

Closed
anthonyhexium opened this issue Aug 5, 2020 · 5 comments
Closed

Comments

@anthonyhexium
Copy link

Hi,

I am using the library with TypeScript. And I am having a TypeScript error every time I want to access a message error.

interface LoginFormInput {
  email: String;
  password: String;
}

const schema = yup.object().shape({
  email: yup.string().email('Veuillez saisir un e-mail valide !').required(),
  password: yup.string().min(6, 'Votre mot de passe doit faire minimum 6 caractères !').required()
});

export default function Login() {
  const { register, handleSubmit, errors } = useForm<LoginFormInput>({
    resolver: yupResolver(schema)
  });

  const onSubmit = (data: LoginFormInput) => {
    console.log(data);
  };

  return (
    {errors.email && <p className="mt-2 text-sm text-red-600">{errors.email.message}</p>}
  )

(I cleaned the code to have only the error part of course)

I could do (errors.email as any).message but do you have a cleaner way ? Or am I missing something maybe.

Am I on the latests version of the library.

Thanks !

@bluebill1049
Copy link
Member

can you reproduce this in a codesandbox?

@bluebill1049 bluebill1049 added the status: need more detail Please follow our issue template. label Aug 5, 2020
@bluebill1049
Copy link
Member

here is a working version: https://codesandbox.io/s/trusting-frog-ssjwo?file=/src/App.tsx

@anthonyhexium
Copy link
Author

@kodebot
Copy link

kodebot commented Aug 6, 2020

why do you use String with capital S in your interface? If you can use primitive type string it seems to resolve your problem

@anthonyhexium
Copy link
Author

Oh my god ... 😞 Thanks. I missed that.

@bluebill1049 bluebill1049 removed the status: need more detail Please follow our issue template. label Jan 24, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants