reactjs - Semantic-ui-react:React/TypeScript 和 Redux 的自定义搜索问题
问题描述
我正在尝试将自定义渲染用于搜索框。我正在使用语义 UI 反应:0.82.5 和打字稿:2.9.1。和 Redux/
我有以下错误:
Type '{ fluid: true; loading: any; results: { id: number; name: string; team: number; location: string;...' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<SearchProps, ComponentState, any>> & Rea...'.
Type '{ fluid: true; loading: any; results: { id: number; name: string; team: number; location: string;...' is not assignable to type 'Readonly<SearchProps>'.
Types of property 'resultRenderer' are incompatible.
Type '({ id, name, team, location, type }: { id: any; name: any; team: any; location: any; type: any; }...' is not assignable to type '(props: SearchResultProps) => ReactElement<any>'.
Types of parameters '__0' and 'props' are incompatible.
Type 'SearchResultProps' is not assignable to type '{ id: any; name: any; team: any; location: any; type: any; }'.
Property 'name' is missing in type 'SearchResultProps'.",
下面是我的代码的摘录。我究竟做错了什么?
const result = [{
id: 73421,
name: "cn-sonar-16",
team: 124,
location: "RTP",
type: "sonarqube-account-rep"
}];
@CSSModules(styles, options)
export class ServicesOverview extends React.Component<any, any> {
public resultRenderer = ({ id, name, team, location, type }) =>
<div key='content' className='content'>
<div> {name}</div>
<div> {team}</div>
<div>{location}</div>
<div >{type}</div>
</div>;
... (omitting code for clarity)
render(){
...
<div styleName="search-container">
<Search
fluid
loading={services.searching}
results={result}
value={services.searchText}
onSearchChange={_.debounce(this.handleSearchChange, 500, {
leading: true
})}
onResultSelect={this.handleResultSelect}
resultRenderer={this.resultRenderer}
/>
</div>
...
const mapStateToProps = state => {
return {
services: state.services,
};
};
export default connect(
mapStateToProps,
mapDispatchToProps
)(ServicesOverview);
解决方案
我认为这是因为您的结果没有输入。并且any
没有属性name
尝试添加:
interface Result {
id: number
name: string
team: number
location: string
type: string
}
...
public resultRenderer = ({ id, name, team, location, type }: Result) =>
...
推荐阅读
- angular - 无法在角度 4 中使用 ngForm - 出现未定义的错误
- exception - 扩展面板底部溢出
- generative-adversarial-network - 任何用于 GAN 的异步训练方法?
- ios - 嵌套的 UITableView 返回单元格但不显示它
- ubuntu - 挂载 NFS 时访问被拒绝
- kotlin - 对象不是抽象的,也没有实现抽象成员
- python - var == False 或者如果不是 var
- python - 理解递归归并排序过程背后的直觉
- javascript - 如何识别网站是否显示了模态弹出窗口?
- selenium-ide - Selenium IDE 表和源选项卡