Reputation: 151
Can't understand why the following code pass flow check:
type Foo = "A" | "B" | "C"
const myFoo: Array<Foo> = []
Isn't Array<Foo>
enforcing the array to have some Foo
type?
I'm a bit confused.
Upvotes: 1
Views: 232
Reputation: 828
The type Array<Foo>
means that all elements in the array must have type Foo
. This is true for the empty array []
: all elements in this array have type Foo
. It just so happens that there are no elements in the array. Flow will enforce that all elements added to the array will be of type Foo
.
Upvotes: 2