Categories
TypeScript Answers

How to create an enum with string values with TypeScript?

Spread the love

Sometimes, we want to create an enum with string values with TypeScript.

In this article, we’ll look at how to create an enum with string values with TypeScript.

How to create an enum with string values with TypeScript?

To create an enum with string values with TypeScript, we can assign a value to each enum entry.

For instance, we write

enum E {
  foo = "foo",
  bar = "bar",
}

to create the enum E that has the values foo and bar.

And we assign them to 'foo' and 'bar' respectively.

Conclusion

To create an enum with string values with TypeScript, we can assign a value to each enum entry.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *