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!
P粉8632950572023-12-24 11:57:57
That's exactly what it means - it doesn't exist in your registered
type. toLocaleLowerCase()
only exists on the string
type - so unless you can map the Registration
type to the string
, it won't work. I see that Registration.fullname
is a string, but it's also optional - meaning it could be undefined, which could also throw an error.