I have a root redux state defined:
interface RootState {
users: User[]
}
In my components I would like to use ConnectedProps
to automatically create the props type from my state mapping and dispatch mapping:
const mapState = (state: RootState) => ({
users: state.users
});
const mapDispatch = {
deleteUser: (id: number) => (deleteUser(id)) // deleteUser action creator defined in another file
}
const connector = connect(
mapState,
mapDispatch
)
type Props = ConnectedProps<typeof connector>
However when I try to map over users in my component with props.users.map(user => {...
I get a type error:
Parameter 'user' implicitly has an 'any' type
.
Why is it treating users
as an Any[]
rather than a User[]
?
Note I do not get this error if I replace Props
with
interface Props {
users: User[]
}
Simply adding the type to my map function solved the issue:
props.users.map((user: User) => {...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.