TypeScript
- languages
- in current work
I came to TypeScript from JavaScript, and the moment I understood what type safety actually meant in practice, there was no going back. It clicked during LoS, a codebase that kept growing, with shared components between mobile and web, state flying everywhere. JavaScript alone would have been chaos. TypeScript gave me interfaces, autocomplete that actually worked, and errors caught before I even ran the code.
I use it in almost everything now: LoS, the Wine Sommelier, the Meeting Intelligence Platform. It's become my default way of thinking about code. I even started writing Python with type hints everywhere as a sort of workaround because I miss it when I'm away from it. That said, it's not without its frustrations. Sometimes strict typing clashes hard with JavaScript's dynamic nature, and it's tempting to silence the compiler with any or //@ts-ignore. Both switch the checks off exactly where the data is least certain, so I'd rather spend the minutes describing it: derive the type from the constant it comes from, or narrow the input with a type guard.
/**
* How strong a computer a game needs, in three steps. 1 runs on almost anything,
* 2 wants a real graphics card, 3 wants a recent, strong one.
*/
export type PowerLevel = 1 | 2 | 3;
export const POWER = [
{ key: "low", level: 1, label: "Light", hint: "Runs on almost anything, integrated graphics included" },
{ key: "mid", level: 2, label: "Medium", hint: "Wants a graphics card, an older one will do" },
{ key: "high", level: 3, label: "Demanding", hint: "Wants a recent gaming PC" },
] as const;
export type PowerKey = (typeof POWER)[number]["key"];
export const POWER_BY_KEY = new Map<string, (typeof POWER)[number]>(POWER.map((p) => [p.key, p]));
export const POWER_BY_LEVEL = new Map<number, (typeof POWER)[number]>(POWER.map((p) => [p.level, p]));