Reputation: 82
I have a union type of object types like:
type Action = { type: 'A' } | { type: 'B' } | { type: 'C' } // and so on
I want to make a union type of their type properties, like:
type ActionType = 'A' | 'B' | 'C' // and so on
Is there a way to do this programmatically in Flow (i.e. so I don't have to manually list out all the string literals to make ActionType
)? I couldn't figure it out using $ObjMap
, $PropertyType
, $Call
, or any combination thereof.
Upvotes: 1
Views: 191
Reputation: 161457
$PropertyType
and $ElementType
both work here.
type ActionType = $PropertyType<Action, "type">;
// OR
type ActionType = $ElementType<Action, "type">;
Upvotes: 2