【发布时间】:2017-12-16 21:55:25
【问题描述】:
我在这里搜索使用流与 redux 的方法时找到了代码示例: https://flow.org/en/docs/frameworks/redux/
特殊的语法是 (action: empty);它只是打算在 switch 语句的默认情况下使用的一点流魔法还是有其他用途?
它看起来像没有返回值类型但带有奇怪类型“空”的参数的不合适的函数类型语句,我找不到关于它的文档。
// @flow
type State = { +value: boolean };
type FooAction = { type: "FOO", foo: boolean };
type BarAction = { type: "BAR", bar: boolean };
type Action = FooAction | BarAction;
function reducer(state: State, action: Action): State {
switch (action.type) {
case "FOO": return { ...state, value: action.foo };
case "BAR": return { ...state, value: action.bar };
default:
(action: empty);
return state;
}
}
【问题讨论】: