29

I have an enum in typscript. I need to convert the value of the enum to string so that I can pass this to an api endpoint. How do I do this? Thanks.

enum RecordStatus {
    CancelledClosed = 102830004,
    Completed = 102830003,
    InProgress = 102830002,
    ShoppingCart = 102830005,
    Submitted = 102830001,
    Unordered = 102830000
}

example:

var submittedStrValue = RecordStatus.Submitted // I want to get "10283001" (note the string value rather than the int value. 
4

1 Answer 1

25

You can just use RecordStatus.Submitted.toString().

Sign up to request clarification or add additional context in comments.

1 Comment

You could always use string enums too, especially if you're going to always want to use the string value, and you're going to explicitly assign a value to each enum.

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.