Skip to content

Strange index signature error if you use $Keys<O> instead of the equivalent literal union inside $ReadOnlyArray #9100

Open
@mwiencek

Description

@mwiencek

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions