1

I have a property which can basically contain 4 possible strings.

At the moment I'm using a simple | however I need to reuse those types else where, however how do I create an interface for just those 4 values:

selectedState?: "" | "IN_PROGRESS" | "SUCCESS" | "ERROR"

I was hoping to do something like:

interface SelectedStates: "" | "IN_PROGRESS" | "SUCCESS" | "ERROR"

and then

selectedState?: SelectedStates

Any ideas appreciated.

1 Answer 1

2

You could use a type alias:

Type aliases create a new name for a type. Type aliases are sometimes similar to interfaces, but can name primitives, unions, tuples, and any other types that you’d otherwise have to write by hand.

Like:

export type SelectedStates = "" | "IN_PROGRESS" | "SUCCESS" | "ERROR";

// Elsewhere
selectedState?: SelectedStates;
Sign up to request clarification or add additional context in comments.

1 Comment

Great, that was it. I just came across it :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.