I have a very basic stateful component where I'm using recompose to add multiple HOC to my component (in my example I only use one for simplicity). For some reason typescript is giving me an error regarding my props going into my component. How can I get rid of this error?
Here's my code:
import * as React from 'react';
import { connect } from 'react-redux';
import { compose } from 'recompose';
interface IStoreState {
readonly sessionState: {
authUser: { email: string; }
}
}
interface IAccountPageProps {
authUser: { email: string }
}
const AccountPage = ({ authUser }: IAccountPageProps ) =>
<div>
<h1>Account: {authUser.email}</h1>
</div>
const mapStateToProps = (state: IStoreState) => ({
authUser: state.sessionState.authUser,
});
export default compose(
connect(mapStateToProps)
)(AccountPage);
And the error I'm getting is:
Argument of type '({ authUser }: IAccountPageProps) => Element' is not assignable to parameter of type 'ComponentType<{}>'.
Type '({ authUser }: IAccountPageProps) => Element' is not assignable to type 'StatelessComponent<{}>'.
Types of parameters '__0' and 'props' are incompatible.
Type '{ children?: ReactNode; }' is not assignable to type 'IAccountPageProps'.
Property 'authUser' is missing in type '{ children?: ReactNode; }'.
If I don't use recompose and instead write
export default connect(mapStateToProps)(AccountPage)
I do not get any errors.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…