|
|
|
|
|
by conaclos
1608 days ago
|
|
Replacing TS enum with JS objects is really tedious: type HttpMethod = keyof typeof HttpMethod
const HttpMethod = {
GET: "GET",
POST: "POST",
} as const
It is even worse with int enum: type HttpMethod = Extract<keyof typeof HttpMethod, number>
const HttpMethod = {
GET: 0,
POST: 1,
0: "GET",
1: "POST",
} as const
My personal "avoid"-rules are:- Avoid enum with negative integers because it generates code that cannot be optimized by the JS engine - Prefer ESM modules to namespaces, because the first can be tree-shaked. |
|
[0] https://news.ycombinator.com/item?id=30010017