Javascript 类型';(事件:FormEvent<;HTMLInputElement>;)=>;无效';不可分配给类型';()=>;任何';
类型“(event:FormEvent)=>void”不可分配给类型“()=>any” 在我的父组件中,我只是传入一个函数,该函数处理子组件的onChange:Javascript 类型';(事件:FormEvent<;HTMLInputElement>;)=>;无效';不可分配给类型';()=>;任何';,javascript,reactjs,typescript,Javascript,Reactjs,Typescript,类型“(event:FormEvent)=>void”不可分配给类型“()=>any” 在我的父组件中,我只是传入一个函数,该函数处理子组件的onChange: <SearchInput handleSearchTyping={this.handleSearchTyping}/> @bind handleSearchTyping(事件:React.FormEvent){ const target=event.target作为HTMLInputElement; const{va
<SearchInput handleSearchTyping={this.handleSearchTyping}/>
@bind
handleSearchTyping(事件:React.FormEvent){
const target=event.target作为HTMLInputElement;
const{value:searchText}=target;
常量搜索=(文本:字符串)=>{
const{searchList}=this.state;
const searchedCoins=findAsset(文本,搜索列表);
this.setState({searchList:searchedCoins});
};
常量clearSearch=()=>{
this.setState({searchList:this.state.saved});
};
const handleUpdate=(num:number)=>(num>1?搜索(searchText):clearSearch();
返回handleUpdate(searchText.length);
}
子项:搜索输入:
import React from 'react'
export const SearchInput = (props: { handleSearchTyping(): void }) =>
<input type="text" placeholder="Search here" onChange={props.handleSearchTyping} />;
从“React”导入React
export const SearchInput=(props:{handleSearchTyping():void})=>
;
还尝试:
interface IProps {
handleSearchTyping(): void;
}
export const SearchInput = (props: IProps) =>
<input type="text" placeholder="Search here" onChange={props.handleSearchTyping} />;
接口IProps{
handleSearchTyping():void;
}
export const SearchInput=(props:IProps)=>
;
进入SearchInput
道具的正确类型是什么?Ah刚刚修复了它:
import React from 'react'
interface IProps {
handleSearchTyping(event: React.FormEvent<HTMLInputElement>): void;
}
export const SearchInput = (props: IProps) =>
<input type="text" placeholder="Search here" onChange={props.handleSearchTyping} />;
从“React”导入React
接口IProps{
handleSearchTyping(事件:React.FormEvent):void;
}
export const SearchInput=(props:IProps)=>
;
需要使用
事件:React.FormEvent
类型。试试这个.handleSearchTyping}/>
import React from 'react'
interface IProps {
handleSearchTyping(event: React.FormEvent<HTMLInputElement>): void;
}
export const SearchInput = (props: IProps) =>
<input type="text" placeholder="Search here" onChange={props.handleSearchTyping} />;