Is it feasible in Typescript to derive a union type from the values of a field within another union type?
type MyUnionType =
| { foo: 'a', bar: 1 }
| { foo: 'b', bar: 2 }
| { foo: 'c', bar: 3 }
// Is there an automatic way to achieve this?
// Like creating a union of the possible values for foo in MyUnionType?
type Foos = 'a' | 'b' | 'c'
I had hoped Pick<MyUnionType, 'foo'>
would work, but it doesn't quite deliver - it returns the desired type nested under a foo
field: { foo: 'a' | 'b' | 'c' }