TypeScript · Senior · Question 68 of 75
Why should a public library avoid enum in its API?
- ✓Correct answer: Enums are nominal and emit runtime code; consumers must import the enum and can't pass equivalent string literals
- 2Enums are slower than objects
- 3Enums don't work in
.d.ts
Explanation
A union of string literals (with an as const object if you need runtime values) is erasable and friendlier to consumers.