1

I have a type like this:

type MyType = "One" | "Two" | "Three" | "Four" | "Five" 

Now, in some cases, not all of the values of MyType are valid. So I want to have a type, which can have the same values as MyType, except a few of them. like this:

type OtherType = "One" | "Two" | "Five" 

Basically, I want the second type to be a limited version of the first type. I'm not sure if this is possible; That's why I'm asking for help to make sure :)

I know I probably should make two different types BTW, but if this would be possible, it would save me from a lot of pain!

Thanks!

1 Answer 1

2

You can use Exclude for this:

type OtherType = Exclude<MyType, "Three" | "Four">; 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.