Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I omit a value in typescript union type

I have a type:

export type Example = ExampleOne | ExampleTwo | ExampleThree;

How do I create a new type ExampleX which only contains ExampleOne or ExampleTwo?

I tried:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

export type ExampleX = Omit<Example, 'ExampleThree'>;

But that doesn’t work?

>Solution :

You’re looking for Exclude rather than Omit, and you don’t want the quotes:

export type ExampleX = Exclude<Example, ExampleThree>;

Playground link

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading