Reputation: 49714
I have a function that can take an Array of numbers or an Array of strings (but not an Array of numbers and strings).
In other words, the Array might resemble [1, 2, 3]
OR ['1', '2', '3']
but NOT [1, '2', 3]
Right now I declare it like so
function fn<T>(options: Array<T>): Array<T> { ... }
but this ^ would allow for Array of any single type (strings, numbers, objects, whatever).
Looking at the docs on Flow's generic types, the only alternative I can think of looks like this
function fn<T: string | number>(options: Array<T>): Array<T> { ... }
but that ^ allows for an Array that contains both strings and numbers, which as explained above, is not what I want...
Surely, there's a way to flow type an Array of strings OR an Array of numbers...?
Upvotes: 0
Views: 477
Reputation: 138267
Array<string> | Array<number>
Which reads as an array of strings or an array of numbers
Upvotes: 3