-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type inference could be smarter with mixed Array types #2507
Comments
I'm running into this with React Native's |
@jkk That's where I originally saw this as well. |
Looks like a bug, case 2 isn't really promising |
Similar issue with a union type of an array. type TerritoryCode = 'US' | 'FR' | 'RE' | //...
type Track = {
territories: Array<TerritoryCode> | TerritoryCode
//...
}
const track: Track = {
territories: [ 'US', 'FR' ]
} I get the following error:
|
Do any one have solution for @acarl005 example code, i have a similiar situation. How can we provide the type of array while initializing the array. |
@gokulbharathi : I tested it out on 0.73.0, and it looks like Flow can handle selecting the correct type in the union of a union and an array. But it still errors out on the union of 2+ arrays. I ended up casting the array like so:
|
Explicitly annotating the array type isn't really a great workaround. |
This now works under |
Flow Version: 0.32.0
Consider the following example:
I'd expect the type inference to know that
[1, 2]
is an array of numbers and accept thefoo([1, 2])
call, but instead I get this error:Obviously I can work around this by adding annotations, but was curious: Is this a solvable problem without annotations or is this just the nature of the complicated problem inferring mixed types?
The text was updated successfully, but these errors were encountered: