我正在使用 JavaScript 和 Typescript 进行开发。我有下面的函数来检查数组是否有重复项,但我收到错误,并且不确定如何解决。以下是错误和代码摘录。
错误:“Registration”类型上不存在属性“toLocaleLowerCase”。ts(2339)
Registration.ts
export interface Registration {
address: string;
comment?: string;
fullname?: string;
}
JS文件
const nameAlreadyExist = (name: any): void => {
const nameExist = filteredRegistrationName.value.findIndex((registrationName) =>
registrationName.fullname.toLocaleLowerCase() === name.toLocaleLowerCase());
nameExist != -1 ? (existNameError.value = true) : (existNameError.value = false);
};
任何见解将不胜感激。谢谢!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
这正是它的含义 - 它不存在于您的
注册类型中。toLocaleLowerCase()仅存在于string类型上 - 因此除非您可以将Registration类型映射到string,否则行不通的。我看到Registration.fullname是一个字符串,但它也是可选的 - 这意味着它可能是未定义的,这也可能引发错误。