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
上,我得到了这个: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)