November 2019
Beginner
804 pages
20h 1m
English
Another useful thing to know is that it is possible to define enums that do not subsist after transpilation by using the const keyword. When doing so, the compiler inlines the values and doesn't transpile the enum at all. This can be useful for reducing the size of the generated JavaScript code. This must only be used as an optimization technique because it hinders the readability of the generated code, so it shouldn't be your default choice.
The following is an example:
const enum TransientEnum {
A,
B
}
console.log(TransientEnum.A); // 0
As you can see, const enums are defined using const enum but are then used normally.
The corresponding JavaScript code is as follows:
"use strict"; console.log(0 /* A */); // 0
Note that the ...
Read now
Unlock full access