Open
Description
Flow version: 0.219.2
type O = {a: 1, b: 2};
type K1 = 'a' | 'b';
// should be equivalent to K1
type K2 = $Keys<O>;
// gives incompatible-cast (expected)
('ab'.split(''): $ReadOnlyArray<K1>);
// gives props-missing (???)
('ab'.split(''): $ReadOnlyArray<K2>);
Expected behavior
I'd expect the ('ab'.split(''): $ReadOnlyArray<K2>);
cast above to throw an incompatible-cast error, like the first one does.
Actual behavior
A prop-missing error is given instead:
12: ('ab'.split(''): $ReadOnlyArray<K2>);
^ Cannot cast `'ab'.split(...)` to read-only array type because an index signature declaring the expected key / value type is missing in `O` [1] in array element. [prop-missing]
References:
12: ('ab'.split(''): $ReadOnlyArray<K2>);
^ [1]
I ran into this issue because I previously had a // $FlowIgnore[incompatible-cast]
to suppress the first error, but that stopped working once I started using $Keys
.
Activity