Posts about typescript

13 posts

Back to the whole garden

  1. GRD 033 #693

    Running TypeScript in Node without a build step

    Node 23 strips types out of the box and TypeScript 5.8 has a flag that keeps your code strippable. For scripts and small services I dropped tsx, though the compiler still has a job.

  2. GRD 030 #741

    Type predicates, and the ones TypeScript 5.5 now writes for you

    filter(Boolean) never narrowed, so every codebase grew a pile of is functions. TypeScript 5.5 infers the simple ones, though not all of them, and a hand-written one can still lie to you.

  3. GRD 029 #B27

    The TypeScript utility types I use

    A hand-rolled mapped type in a code review sent me back to the handbook, because most of what we need already ships with TypeScript. These are the ones I use, plus a trap in Omit and the new NoInfer from 5.4.

  4. GRD 025 #945

    The tsconfig module settings I finally understand

    module, moduleResolution and the new verbatimModuleSyntax were three knobs I turned until the errors went away. TypeScript 5.0 finally made me read what they do, and now I know why my Vite app and my Node service need different ones.

  5. GRD 024 #A73

    Deterministic randomness for a roguelike

    A seed should give you the same dungeon every time, but it won't if the combat rolls and the level generator share one random number generator. The fix is a separate stream for each thing that rolls.

  6. GRD 023 #A15

    How I type React components in TypeScript

    After a few years of typing React components I'm down to a handful of shapes, and I let the compiler infer the rest. React.FC isn't one of them anymore.

  7. GRD 022 #631

    TypeScript trusts your API too much, so I added Zod

    A backend rename turned a typed field into undefined and the compiler never blinked, because types are gone at runtime. So now the data gets checked where it comes in.

  8. GRD 020 #42A

    Why I stopped writing enums in TypeScript

    Enums were the first thing I reached for when I started with TypeScript. Then I read what they compile to. A const object does the same job with less magic, and TypeScript 4.9 just added the piece that was missing.

  9. GRD 019 #249

    An energy scheduler for turn-based games

    Move the player, then move every monster once: that loop works until the first bat. Angband's energy system fixes it in forty lines, and the browser loop around it stops at the player and waits for a key.

  10. GRD 015 #13B

    Discriminated unions: the TypeScript feature I'd teach first

    Three booleans for one request gave us a spinner on top of an error message. One union with a status field fixed it, and now the compiler tells me when I forget a case.

  11. GRD 011 #6B2

    Dijkstra maps: the roguelike trick I use for everything

    One flood fill from the goal tells every monster on the level which way to walk, and a negated copy tells them which way to run. Brian Walker wrote it up a decade ago and I keep finding new uses for it.

  12. GRD 010 #841

    Field of view with symmetric shadowcasting

    Rogue lit whole rooms and called it a day. Rays and shadowcasting came later, along with a bug where the monster could see you but you couldn't see it. Symmetric shadowcasting fixed that, and this is my TypeScript port.

  13. GRD 009 #394

    How Rogue drew its dungeon

    Before BSP trees and cellular automata there was a three by three grid with a room in each cell. It's still the generator I write first, and it fits in a hundred lines.