I'm currently exporting 2 action creators:
export const login = (payload: $PropertyType<Actions.Login, 'payload'>): Actions.Login => ({
type: LOGIN,
payload,
})
export const logout = (payload: $PropertyType<Actions.Logout, 'payload'>): Actions.Logout => ({
type: LOGOUT,
payload,
})
These are their respective `actions:
export type Login = {
type: ActionType,
payload: {
username: string,
password: string,
},
}
export type Logout = {
type: ActionType,
payload: null,
}
In another file, I import the creators using the wildcard syntax
import * as Actions from ...
I'm then trying to extract from these actions the shape of their return type to use as the action type for my reducers.
What I'm trying to obtain is the following (I think, as I'm assuming this is what Flow is expecting to satisfy the reducers requirements – a type property):
type Action = {
login: { type: '', payload: '' },
logout: { type: '', payload: '' }
}
I've reached this function:
type Action = $ObjMap<typeof Actions, <V>(V) => $Call<V>>
Which returns the following:
Action: type Action = {
login: Login,
logout: Logout
}
Which is indeed the actions returned from those creators. However, Flow within the reducer is not picking up on the type property within that action.
The reducer looks like this:
const reducer = (state: State = initialState, action: Action): State => {
switch (action.type) {
case LOGIN:
return { ...state }
default:
return state
}
}
With the error at action.type being:
[flow] property `type` is missing in object type [1]. (References: [1])
Any help into writing a better, generic function is much appreciated. Thank you.