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.