I would like to use an imported constant from a package in a flow literal type and static check the switch;
Is there a way to do this? (example bellow)
// 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
}
}
Flow
does not support to use of variables containing constants in type definitions.
You have to either use the string value itself or a support data type in your definition.
This post was a similar issue if you'd like to review it as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With