我不明白为什么会出现这种错误
Parameter 'props' implicitly has an 'any' type.
因为我之前使用iterface在构造函数方法中使用了props。 当我遇到问题时,我将完整的反应组件放在下面
import { connect } from 'react-redux';
import { FetchPokemon } from '../../actions';
import * as React from 'react';
import { HeaderComponent } from './HeaderComponent';
import {IStoreState} from '../../types';
interface IProps {
pokemon: object[];
FetchPokemon: () => void;
}
interface IState {
example: boolean
}
class HeaderContainer extends React.Component<IProps, IState> {
constructor(props) {
super(props);
this.state = {
example: false
}
this.FetchAction = this.FetchAction.bind(this);
}
public FetchAction = () => {
this.props.FetchPokemon()
}
public render() {
return (
<div>
{console.log(this.props)}
<HeaderComponent fetchAction={this.FetchAction}/>
</div>
)
}
}
const mapStateToProps = (state: IStoreState) => ({
pokemon: state.fetchPokemon
})
export default connect(mapStateToProps, {FetchPokemon})(HeaderContainer) as any;
&#13;
有人有一些想法吗?
答案 0 :(得分:1)
TypeScript的严格性要求您清楚某些类型和对象,具体取决于您的转换器配置。当谈到React和TypeScript时,建议按如下方式编写构造函数:
class Component extends React.Component<Props, State> {
public constructor(props: Props) {
super(props as any);
}
}