我在redux中有一整套键入的动作创建器,我绑定到react组件中的props。我很好奇是否为组件道具添加类型是标准做法,即使他们收到的动作创建者已经输入过。
// Action Creator: Here I am typing the action creator for the first time
export interface FetchingUserSuccessReturn {
type: string;
uid: string;
user: any;
timestamp: number;
}
export function fetchingUserSuccess(uid: string, user: any, timestamp: number): FetchingUserSuccessReturn {
return {
type: FETCHING_USER_SUCCESS,
uid,
user,
timestamp
};
}
是否通常会忽略组件道具界面,因为道具已经被键入(作为动作创建者)?
// Component receiving action creator
// It feels like I'm re-typing the action creators in this interface
interface MainContainerProps {
fetchingUserSuccess: (uid: string, user: any, timestamp: number) => FetchingUserSuccessReturn;
}
export default connect(
() => (),
(dispatch) => {
return bindActionCreators({
fetchingUserSuccess: userActionCreators.fetchingUserSuccess,
}, dispatch);
}
)(MainContainer);
export class MainContainer extends React.Component<MainContainerProps, any> {
...