0
例は@flowtype.org/tryです。ここでは、条件付きの型の洗練が両方の例で動作すると期待していますが、単純な型だけで動作します。私がArray.filter
を紹介しても、洗練は効きません。これは私の部分の流れや誤った使い方のバグですか?フィルタによって打ち負かされたフローユニオンタイプの洗練
/* @flow */
export type Action =
{| type: 'ACTION1', payload: string |}
| {| type: 'ACTION2', payload: number |}
| {| type: 'ACTION3' |}
const things = (state: Array<number> = [], action: Action): Array<number> => {
if (action.type === 'ACTION2') {
return state.filter((thing) => { return thing !== action.payload })
} else {
return state
}
}
things([1, 5], { type: 'ACTION2', payload: 5 })
const add = (state: number = 0, action: Action): number => {
if (action.type === 'ACTION2') {
return state + action.payload
} else {
return state
}
}
add(0, { type: 'ACTION2', payload: 5 })
次のエラーを生成します。
10: return state.filter((thing) => { return thing !== action.payload })
^property `payload`. Property not found in
6: | {| type: 'ACTION3' |} ^object type