Reputation: 2496
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.
Upvotes: 18
Views: 6428
Reputation: 1089
Try using Extract
instead of Pick
:
type FooType = 'foo' | 'bar' | 'baz';
type Extracted = Extract<FooType, 'foo' | 'bar'>;
// type Extracted = 'foo' | 'bar'
Upvotes: 25