【发布时间】:2016-09-14 06:02:59
【问题描述】:
在当前的 react/redux 项目中使用 flowtype。
我在我的 actions.js 文件中定义了一个不相交的联合类型:
export type ArticleAction =
{ type: 'ARTICLE_SET_EDITION' }
| { type: 'ARTICLE_BLABLA', blip: string };
然后在我的减速器中我有
import type { ArticleAction } from './actions';
[...]
const articlesReducer = (state: any = initialState, action: ArticleAction): any => {
if (action.type === 'ARTICLE_BLABLA') {
const test = action.blip.shoups;
return test;
}
}
Flow 没有检测到问题。
但是!如果我直接在 reducer.js 中声明 ArticleAction,它会识别 action.blip.shoups 是无效的,因为 blip 是一个字符串。
知道我做错了什么吗? 谢谢
【问题讨论】:
-
actions.js 中有
// @flow吗? -
是的,我确实有 // @flow 在他们两个中
标签: javascript redux flowtype