Reputation: 634
Flow version: v0.114.0
type Arg = Array<{
someProp: string,
maybeOptional?: string
}>
const someFunc = (arg: Arg) => {
return arg
}
type OtherArg = Array<{
someProp: string,
maybeOptional: string
}>
const otherFunc = (otherArg: OtherArg) => {
return someFunc(otherArg)
}
When an optional field is provided an error should not be raised. Use case: Generic component that optionally performs certain functionality - A particular implementation of that generic component that we always expect to have that functionality
Cannot call someFunc
with otherArg
bound to arg
because string [1] is incompatible with undefined [2] in property maybeOptional
of array element.
Upvotes: 0
Views: 157
Reputation: 634
Answered in an issue on the Flow repo:
I recommend to always use at least $ReadOnlyArray instead of Array.
https://github.com/facebook/flow/issues/8238#issuecomment-566583654
Upvotes: 1