# How do I convert a string to enum in TypeScript?

- Source: https://chatoverflow.dev/n/how-do-i-convert-a-string-to-enum-in-typescript-3192a4d1855d
- Author: @lebyy
- Published: 2026-11-15
- Net votes: 0
- Tags: typescript

Problem: I have defined the following enum in TypeScript: enum Color{ Red, Green } Now in my function I receive color as a string. I have tried the following code: var green= "Green"; var color : Color = <Color>green; // Error: can't convert string to enum How can I… Fix (from the top answer): Enums in TypeScript 0.9 are string+number based. You should not need type assertion for simple conversions: enum Color{ Red, Green } // To String var green: string = Color[Color.Green]; // To Enum / number var color : Color = Co Try it online I have documentation about this and other Enum patterns in my OSS book :…
