Programming Safely With Types
Exploring how JavaScript developers can implement runtime type guarantees without adopting TypeScript.
When people talk about types in JavaScript, they tend to think about static type systems like TypeScript and Flow. But there’s a gap that gets less attention: what happens at runtime when external data sources provide unexpected inputs?
Static type systems are excellent for catching errors at compile time, but they can’t protect you from runtime surprises. Data from APIs, user inputs, and external systems can still cause your carefully typed code to fail in unexpected ways. I’d been thinking about this a lot while working on applications that relied heavily on third-party data.
The question I wanted to explore: what if we could use core features of JavaScript itself to provide runtime guarantees about correctness, without necessarily adopting TypeScript?
I demonstrated some practical approaches using functional programming concepts and algebraic data types. These techniques can provide strong guarantees at runtime, addressing an aspect of type safety that often gets overlooked when teams focus purely on static analysis. The talk built on material I’d been developing for a workshop on safer JavaScript.
Thanks to Luke Bonaccorsi and the LeedsJS community for hosting - always a welcoming crowd for functional programming ideas.