-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Typing issues with react-redux connect and class components #55
Comments
Could you please post a full error message? |
|
My guess is that this is because |
I think const mapDispatchToProps = (dispatch) => {
doSomething: (x: string) => dispatch(doSomething(x)),
}; |
@aikoven changing to @suutari-ai the react-redux API seems to support both versions of specifying |
I am also getting an error in this case, but with a different error message:
|
@supermihi I'm sorry for not answering for so long. I took a closer look and it still seems that this has to do with I managed to fix the error you get by specifying type arguments explicitly: connect<{}, Props>(null, mapDispatchToProps)(MyComponent); // no error @bschlenk Could you please check if the above trick fixes your case? |
@aikoven Thanks for providing the workaround! |
@supermihi it works fine, the only thing you should do, is just define the type of component props clearly. you can refer to this: import * as React from 'react';
import {connect} from 'react-redux';
import {TodoAppState, TodoItemState} from '@src/types/todoApp';
const TodoItem = ({id, isComplete, name}) => (
<li>
<input type="checkbox" defaultChecked={isComplete}/>
{name}
</li>
);
type PropsType = {
todos: TodoItemState[];
};
class TodoList extends React.Component<PropsType> {
render() {
return (
<div className="Todo-list">
<ul>
{this.props.todos.map(todo => <TodoItem key={todo.id} {...todo}/>)}
</ul>
</div>
);
}
}
export default connect(
(state: TodoAppState) => ({
todos: state.todos,
})
)(TodoList); |
Not sure if this is related to #51 or #32, but I have issues with typescript-fsa in connection to react-redux'
connect
and class components.In the following example, the class component version does not compile, but the functional component version does:
Both work if I declare
Props
asBut I obviously do not want to couple the component to redux-specific stuff. Using typescript 2.8 and the most up-to-date version of all packages. Any ideas?
The text was updated successfully, but these errors were encountered: