0

Please I have problem with TS, if I uncomment the line 3 the value of the email will become ''.. How can I remove the TS error Property 'email' does not exist on type '{}'?

export default function loginValidate(values: any) {
  let errors = {
    // email:'', //handling = Property 'email' does not exist on type '{}'
    // password: '', //handling = Property 'password' does not exist on type '{}'
  };


  if (!values.email) {
    errors.email = 'Email Required';
  } else if (!/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i.test(values.email)) {
    errors.email = 'Invalid email address';
  }

  //Validation for password
  if (!values.password) {
    errors.password = 'Password Required';
  } else if (values.password.length < 6 || values.password.length > 30) {
    errors.password = "Must be greater than 6 and less than 30 characters"
  } else if (values.password.includes(" ")) {
    errors.password = "Invalid Password";
  }

  return errors;

}

enter image description here

Fixed

let errors = {} to let errors: any = {}

erwin
  • 99
  • 2
  • 9

0 Answers0