[英]Why is ConnectedProps not inferring the correct type?
我有一個根 redux state 定義:
interface RootState {
users: User[]
}
在我的組件中,我想使用ConnectedProps
從我的 state 映射和調度映射中自動創建道具類型:
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>
但是,當我嘗試使用props.users.map(user => {...
在我的組件中對用戶進行 map 時...我收到類型錯誤:
Parameter 'user' implicitly has an 'any' type
。
為什么將users
視為Any[]
而不是User[]
?
請注意,如果我將Props
替換為
interface Props {
users: User[]
}
只需將類型添加到我的 map function 即可解決問題:
props.users.map((user: User) => {...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.