Javascript TypeScript-实用程序方法中的错误

Javascript TypeScript-实用程序方法中的错误,javascript,reactjs,typescript,interface,Javascript,Reactjs,Typescript,Interface,我有以下实用方法。它有两个参数,inputValue和selectOptions export interface SelectType { label: string; value: string; } const checkCaseSensitiveSelectUtil = (inputValue: SelectType, selectOptions: SelectType[]): any => { const exactValueExists = selectOptio

我有以下实用方法。它有两个参数,
inputValue
selectOptions

export interface SelectType {
  label: string;
  value: string;
}

const checkCaseSensitiveSelectUtil = (inputValue: SelectType, selectOptions: SelectType[]): any => {
  const exactValueExists = selectOptions.find(input => input.value === inputValue);
  const valueIsNotEmpty = inputValue.trim().length;

  return !exactValueExists && valueIsNotEmpty;
};

export default checkCaseSensitiveSelectUtil;
但我得到以下错误: 1.在
input.value===inputValue
上,我得到以下结果:

(parameter) input: SelectType
This condition will always return 'false' since the types 'string' and 'SelectType' have no overlap.ts(2367)
  • trim
    上,我得到了这个:
  • 任何人都知道如何真正消除这两个错误。我的意思是,由于参数是这种类型的,所以我唯一的选择就是将它们转换为任意?

    1。

    您正在将
    input.value
    (字符串类型)与
    inputValue
    (类型
    SelectType
    )进行比较。一种可能的解决方案是将
    input
    的值与
    inputValue
    的值进行比较

    selectOptions.find(输入=>input.value==inputValue.value);
    
    2.

    const valueIsNotEmpty=inputValue.trim().length;
    
    由于
    inputValue
    不是该值,而是
    SelectType
    的一个实例,因此不能仅对其进行修剪

    尝试获取值(字符串)

    const valueIsNotEmpty=inputValue.value.trim().length;
    

    <>你应该考虑重命名变量。命名有点混乱;)

    您的参数inputValue不是strin而是object!inputValue:SelectType。。。您可能需要比较此对象的属性。。。nput.value==inputValue.label(或inputValue.value)对不起。我不明白你在说什么。你能提供更多关于这个问题的信息吗?也许是个例子?抱歉给你添麻烦了
    Property 'trim' does not exist on type 'SelectType'.ts(2339)