Typescript: pick from type not interface?


I have a type:

export type MyType = 'something' | 'another' | 'else';

Then I would like to use just some of its options:

Interface MyInterface {
   selection: Pick<MyType, 'something' | 'another'>

But getting the error type doesn't satisfy the constraint

Is it not possible to use Pick on types but only on interfaces?

>Solution :

Pick is about properties. You need to use Extract:

type MyType = 'something' | 'another' | 'else';

interface MyInterface {
   selection: Extract<MyType, 'something' | 'another'>;

Leave a Reply Cancel reply