방금 flowtype을 배우기 시작했고 마음에 분명하지 않은 두 가지 사항을 이해하기 위해 도움이 필요합니다.flowtype을 사용하여 비동기 액션 제작자를 바인딩하는 방법은 무엇입니까?
예를 들어 https://github.com/reactjs/redux/blob/master/examples/todos-flow를 사용하여, 나는 종류의 제어이 경우, https://github.com/flowtype/flow-typed의 형식 정의하지 않고 작업 할 수있는 방법을 궁금해 : https://github.com/flowtype/flow-typed/blob/master/definitions/npm/redux_v3.x.x/flow_v0.33.x-/redux_v3.x.x.js은?
redux 정의를 사용하는 경우 비동기 작업 작성자를 바인딩하려고하면
bindActionCreators
의 유효성 검사가 실패합니다 (나는 redux-thunk를 사용하고 있습니다).
redux-thunk를 사용할 때 플로우 및 바인드 비동기 액션 작성자를 계속 사용하는 방법은 무엇입니까?
코드 샘플 (https://gist.github.com/momsse/323c228e8c5e264067039b8446cd890f) :
import { bindActionCreators } from 'redux';
import type { Dispatch } from 'redux';
type Action = { type: 'SET_PROFILE', profile: Object };
/**
* Based on https://github.com/gaearon/redux-thunk/blob/master/index.d.ts
*/
type ThunkAction = (dispatch: Dispatch<Action>,
getState:() => any,
extraArgument: any) => any;
type Profile = {
name: string,
team: string
}
// Async actions creator
function setProfile(profile: Profile): ThunkAction {
return dispatch => setTimeout(() => dispatch({ type: 'SET_PROFILE', profile }), 2000);
}
const profileActionCreators = { setProfile };
type Props = {
actions: {
setProfile: (profile: Profile) => ThunkAction,
}
}
function mapDispatchToProps(dispatch: Dispatch<Action>): Props {
return {
actions: bindActionCreators(profileActionCreators, dispatch)
};
}
오류 :
40: actions: bindActionCreators(profileActionCreators, dispatch)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function call. Function cannot be called on any member of intersection type
40: actions: bindActionCreators(profileActionCreators, dispatch)
^^^^^^^^^^^^^^^^^^ intersection
Member 1:
49: declare function bindActionCreators<A, C: ActionCreator<A, any>>(actionCreator: C, dispatch: Dispatch<A>): C;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ polymorphic type: function type. See lib: flow-typed/npm/redux_v3.x.x.js:49
Error:
49: declare function bindActionCreators<A, C: ActionCreator<A, any>>(actionCreator: C, dispatch: Dispatch<A>): C;
^^^^^^^^^^^^^^^^^^^^^ function type. Callable signature not found in. See lib: flow-typed/npm/redux_v3.x.x.js:49
40: actions: bindActionCreators(profileActionCreators, dispatch)
^^^^^^^^^^^^^^^^^^^^^ object literal
Member 2:
50: declare function bindActionCreators<A, K, C: ActionCreators<K, A>>(actionCreators: C, dispatch: Dispatch<A>): C;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ polymorphic type: function type. See lib: flow-typed/npm/redux_v3.x.x.js:50
Error:
13: declare type Dispatch<A: { type: $Subtype<string> }> = (action: A) => A;
^^^^^^^^^^^^^^^^^^^^^^^^^^ property `type` of object type. Property not found in. See lib: flow-typed/npm/redux_v3.x.x.js:13
21: function setProfile(profile: Profile): ThunkAction {
^^^^^^^^^^^ function type