Why flow can't infer that OneActionType can be used where ActionType is used in following example:
/* @flow */
type ActionTypes = 'ONE' | 'TWO' | 'THREE'
type ActionType = {
type: ActionTypes
}
type OneActionType = {
type: 'ONE';
payload: string
}
// this is ok:
// (x:OneActionType) => (x.type:ActionTypes)
// this is not:
(x:OneActionType) => (x:ActionType)
ActionType.type is read/write. OneActionType.type is only 'ONE' but if is treated as a ActionType it could have 'TWO' or 'THREE' assigned to it, violating its type.
You need to mark ActionType.type as covariant (read only): Try Flow
@jesseschalken thank you!
Leave here good reading about variance in flow.
Most helpful comment
ActionType.typeis read/write.OneActionType.typeis only'ONE'but if is treated as aActionTypeit could have'TWO'or'THREE'assigned to it, violating its type.You need to mark
ActionType.typeas covariant (read only): Try Flow