I am developing using JavaScript and Typescript. I have the following function to check if an array has duplicates, but I'm getting an error and not sure how to fix it. Below are the errors and code excerpts.
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 insights would be greatly appreciated. Thanks!
That's exactly what it means - it doesn't exist in your
registered
type.toLocaleLowerCase()
only exists on thestring
type - so unless you can map theRegistration
type to thestring
, it won't work. I see thatRegistration.fullname
is a string, but it's also optional - meaning it could be undefined, which could also throw an error.