With the const modifier in place, the compiler will not emit any mapping code for our MediaTypes enum. Instead, it will inline the value for each enum member at all use sites, potentially saving a few bytes and the overhead of the property access indirection:

But what if, for some reason, we need access to the mapping object at runtime?

Emitting a const Enum with preserveConstEnums

Sometimes, it might be necessary to emit the mapping code for a const enum, for instance when some piece of JavaScript code needs access to it. In this case, you can turn on the preserveConstEnums compiler option in your tsconfig.json file: