Home > other >  Error: Property does not exist on type 'Registration'.ts(2339)
Error: Property does not exist on type 'Registration'.ts(2339)

Time:10-28

I am developing in JavaScript and Typescript. I have the function below that checks an array for duplicates but I am getting an error and I'm not sure exactly how to resolve. Below is the error and an excerpt of the code.

Error: Property 'toLocaleLowerCase' does not exist on type 'Registration'.ts(2339)

Registration.ts

  export interface Registration {
   address: string;
   comment?: string;
   fullname?: string;
  }

JS file

const nameAlreadyExist = (name: any): void => {
    const nameExist = filteredRegistrationName.value.findIndex((registrationName) => 
       registrationName.fullname.toLocaleLowerCase() === name.toLocaleLowerCase());
 
    nameExist != -1 ? (existNameError.value = true) : (existNameError.value = false);
   };

Any insight would be much appreciated. Thanks!

CodePudding user response:

That's exactly what it means - it doesn't exist on your Registration type. toLocaleLowerCase() only exists on type string - so unless you can map the Registration type to a string, it won't work. I see that Registration.fullname is a string, but it is also optional - meaning that it is possibly undefined, which could also be throwing the error.

  • Related