Hacker News new | ask | show | jobs
by RussianCow 1426 days ago
To add to this, the reason it’s important for TypeScript to support string literals as values instead of using enums or something new is interop with existing JS. For example, think of an event handler where you pass the event name as the first argument; you can ensure at compile-time that an invalid event name isn’t passed.
1 comments

Or more importantly, varying the event type based on the event name.

e.g. addEventListener("click", (MouseEvent): void) versus addEventListener("input", (InputEvent): void)