首页  >  问答  >  正文

标题重写为:类型 'Registration' 上不存在属性:Error: Property does not exist on type 'Registration'.ts(2339)

我正在使用 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);
   };

任何见解将不胜感激。谢谢!

P粉798010441P粉798010441301 天前404

全部回复(1)我来回复

  • P粉863295057

    P粉8632950572023-12-24 11:57:57

    这正是它的含义 - 它不存在于您的注册类型中。 toLocaleLowerCase() 仅存在于 string 类型上 - 因此除非您可以将 Registration 类型映射到 string,否则行不通的。我看到 Registration.fullname 是一个字符串,但它也是可选的 - 这意味着它可能是未定义的,这也可能引发错误。

    回复
    0
  • 取消回复