In the ever-evolving world of Typescript transpilers, there is a noticeable shift towards per-module transpilation to boost build speed. However, this approach comes at a cost - it impedes cross-module const enum
usage as type information is required for their transpilation.
I find myself dealing with a plethora of const enums
which, without the inlining feature that const
offers:
- Tend to balloon in size even after minification due to lengthy property names
- Reveal internal backend property names that should remain private
Currently, I generate these const enum
definitions from backend native code. To provide an example, imagine being employed at Apple and having an extensive const enum encompassing every hardware device.
const enum HardwareType {
Apple1 = 0,
// ...
iPhoneX = 412,
// ...
iPhoneUltraXD = 499, // Hypothetical unannounced iPhone
}
Simply switching const enum HardwareType
to enum HardwareType
, besides enlarging my bundle size, would inadvertently expose the new "iPhone Ultra XD" to the public.
Although tools like Terser offer support for --mangle-props, using it raises concerns mentioned in official documentation. Moreover, implementing a regex pattern to encompass every single HardwareType
seems cumbersome. Bear in mind, the aforementioned scenario is just a glimpse; in reality, I have numerous enums with hundreds of values each.
While I strive to embrace cutting-edge technology for bundling applications, I can't help but wonder if there's a more efficient solution out there for compile-time inlining of constant values?