TSConfig
preserveConstEnums
Do not erase const enum declarations in generated code. const enums provide a way to reduce the overall memory footprint
of your application at runtime by emitting the enum value instead of a reference.
For example with this TypeScript:
tsTryconst enumAlbum {JimmyEatWorldFutures = 1,TubRingZooHypothesis = 2,DogFashionDiscoAdultery = 3,}constselectedAlbum =Album .JimmyEatWorldFutures ;if (selectedAlbum ===Album .JimmyEatWorldFutures ) {console .log ("That is a great choice.");}
The default const enum behavior is to convert any Album.Something to the corresponding number literal, and to remove a reference
to the enum from the JavaScript completely.
tsTry"use strict";const selectedAlbum = 1 /* Album.JimmyEatWorldFutures */;if (selectedAlbum === 1 /* Album.JimmyEatWorldFutures */) {console.log("That is a great choice.");}
With preserveConstEnums set to true, the enum exists at runtime and the numbers are still emitted.
tsTry"use strict";var Album;(function (Album) {Album[Album["JimmyEatWorldFutures"] = 1] = "JimmyEatWorldFutures";Album[Album["TubRingZooHypothesis"] = 2] = "TubRingZooHypothesis";Album[Album["DogFashionDiscoAdultery"] = 3] = "DogFashionDiscoAdultery";})(Album || (Album = {}));const selectedAlbum = 1 /* Album.JimmyEatWorldFutures */;if (selectedAlbum === 1 /* Album.JimmyEatWorldFutures */) {console.log("That is a great choice.");}
This essentially makes such const enums a source-code feature only, with no runtime traces.