Use external constant when defining stream literal type
I would like to use an imported constant from a package in a stream literal type and a static check of a switch;
Is there a way to do this? (example below)
// action/types.js
import { REHYDRATE } from 'redux-persist/constants'
export type FooBar = {
foo: number,
bar: string,
};
export type Action
= { type: 'FETCH_REQUEST', data: FooBar[] }
| { type: REHYDRATE, payload: any } // <== this do not work
;
// reducer.js
import { REHYDRATE } from 'redux-persist/constants'
export default function (state: State = initialState, action: Action)
switch (action.type) {
case 'FETCH_REQUEST':
// do something with action.data
case REHYDRATE: { // <= flow says: uncovered code
// do something with action.payload
default:
return state
}
}
+3
source to share