从联合类型对象中的属性创建流联合类型的字符串
Making a Flow union type of strings from properties in a union type of objects
我有一个联合类型的对象类型,例如:
type Action = { type: 'A' } | { type: 'B' } | { type: 'C' } // and so on
我想为它们的类型属性创建一个联合类型,例如:
type ActionType = 'A' | 'B' | 'C' // and so on
有没有办法在 Flow 中以编程方式执行此操作(也就是说,我不必手动列出所有字符串文字来制作 ActionType
)?我无法使用 $ObjMap
、$PropertyType
、$Call
或其任意组合来计算。
$PropertyType
and $ElementType
都在这里工作。
type ActionType = $PropertyType<Action, "type">;
// OR
type ActionType = $ElementType<Action, "type">;
我有一个联合类型的对象类型,例如:
type Action = { type: 'A' } | { type: 'B' } | { type: 'C' } // and so on
我想为它们的类型属性创建一个联合类型,例如:
type ActionType = 'A' | 'B' | 'C' // and so on
有没有办法在 Flow 中以编程方式执行此操作(也就是说,我不必手动列出所有字符串文字来制作 ActionType
)?我无法使用 $ObjMap
、$PropertyType
、$Call
或其任意组合来计算。
$PropertyType
and $ElementType
都在这里工作。
type ActionType = $PropertyType<Action, "type">;
// OR
type ActionType = $ElementType<Action, "type">;