【发布时间】:2019-10-07 15:01:49
【问题描述】:
一切都好吗?
我在理解问题时感到困惑,使用带有反应的键入文本,当连接或使用组件还原时,它会出现此错误并且无法理解,做一些研究,但答案很混乱
错误:
Argument of type 'typeof Beds' is not assignable to parameter of type 'ComponentType<Matching<{ beds: DataBedsTypes[]; } & typeof import("/Users/keven/Documents/carenet/orquestra-frontend/src/Beds/action"), Props>>'.
Type 'typeof Beds' is not assignable to type 'ComponentClass<Matching<{ beds: DataBedsTypes[]; } & typeof import("/Users/keven/Documents/carenet/orquestra-frontend/src/Beds/action"), Props>, any>'.
Types of parameters 'props' and 'props' are incompatible.
Type 'Matching<{ beds: DataBedsTypes[]; } & typeof import("/Users/keven/Documents/carenet/orquestra-frontend/src/Beds/action"), Props>' is not assignable to type 'Readonly<Props>'.
Types of property 'loadBeds' are incompatible.
Type '(data: DataBedsTypes[]) => { type: BedsTypes; payload: DataBedsTypes[]; }' is not assignable to type '() => void'. TS2345
46 | mapStateToProps,
47 | mapDispatchToProps,
> 48 | )(Beds);
我的组件
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { bindActionCreators, Dispatch } from 'redux';
import { Row, Col } from 'config/styles';
import { ApplicationState } from 'config/store';
import { DataBedsTypes } from './types';
import * as BedsActions from './action';
import Bed from './Bed';
interface StateProps {
beds: DataBedsTypes[];
}
interface DispatchProps {
loadBeds(): void;
}
type Props = StateProps & DispatchProps;
class Beds extends Component<Props> {
componentWillMount() {
const { loadBeds } = this.props;
loadBeds();
}
render() {
const { beds } = this.props;
return (
<Row>
{beds.map((b: DataBedsTypes) => (
<Col key={b.pid} md={16.666} lg={10}>
<Bed {...b} />
</Col>
))}
</Row>
);
}
}
const mapStateToProps = (state: ApplicationState) => ({ beds: state.beds.data });
const mapDispatchToProps = (dispatch: Dispatch) => bindActionCreators(BedsActions, dispatch);
export default connect(
mapStateToProps,
mapDispatchToProps,
)(Beds);
【问题讨论】:
标签: reactjs typescript redux