I have a union type, and I'd like to pick certain values from the union type. Is this possible? I've tried to use 'Pick', but this doesn't work on the union type.
e.g.
type FooType = 'foo' | 'bar' | 'baz';
type Extracted = : Pick<FooType, 'foo' | 'bar'>; // should contains only 'foo' and 'bar'
I've now tried various strategies, but cannot get this to work.
Try using Extract instead of Pick:
type FooType = 'foo' | 'bar' | 'baz';
type Extracted = Extract<FooType, 'foo' | 'bar'>;
// type Extracted = 'foo' | 'bar'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With