Trying to incorporate Flow into a Redux codebase has been my current challenge. As someone new to Flow, I have some experience with TypeScript.
My goal is to detect incorrect action types within the reducer function.
type Action =
| { type: 'sample' }
| { type: 'django' }
;
type State = {
content: string,
};
const reducer = (state: State, action: Action): State => {
switch (action.type) {
// OK
case 'sample':
return { content: '' };
// Should raise a type error, because the action type
// will never be equal to "error"
case 'error':
return { content: '' };
default:
return { content: '' };
}
};
Try it in the Flow Playground
Try it in TypeScript Playground
I am puzzled as to why Flow fails to catch the error in this particular scenario. Even though I explicitly set the type to be 'sample' or 'django', Flow still infers the type property as a string.
Can anyone point out what I might be missing?
Thanks!