【发布时间】:2017-11-18 00:04:30
【问题描述】:
我是 flowtypes 的新手,想在输入这个 reducer 时寻求帮助。
// @flow
type State = {
[id: string]: boolean
};
type Action = { type: 'SET_ID', id: number, someValue: string };
function reducer(state: State, action: Action): State {
switch (action.type) {
case 'SET_ID':
const { id, someValue } = action;
return { [id]: someValue };
default:
(action: empty);
return state;
}
}
我正在传递带有 id 作为数字和 someValue 作为字符串的操作,但状态 id 应该是字符串,而 someValue 应该是布尔值。 Flow 产生 0 个错误。有什么想法吗?
谢谢!
【问题讨论】: