Ideas Into Software

Musings on writing code

Exhaustive Switches in TypeScript

Let's say we all love ice cream. So we define the following enum in TypeScript: enum IceCreamTaste { awesome, meh, dunnoYet } And now we want a switch that returns an answer to your friend's question "How does your ice cream taste?". Like so: function getAnswer(taste: IceCreamTaste) { switch (taste) { case IceCreamTaste.awesome: return `It's like a party in my mouth!`; case

TypeScript Module Declaration Vs Augmentation

Just a quick writeup on a simple but perhaps not an entirely obvious feature of TypeScript. TypeScript modules are written in one of two modes: declaration mode or augmentation mode. The difference is that in declaration mode, you can declare new top-level declarations - wow, that's a mouthful - but you can't update existing ones whereas in augmentation mode it's

Typescript: Omit And Projection Types

Typescript 2 introduced a number of useful mapped types such as Pick or Partial. However sometimes the predefined ones just don't cut it. Here's two new types you can use to make your life easier. Omit Pick is handy when you need to create a new type from an existing interface with only the specified keys. Which is great but

Routing Emails Through Meteor Server

Some time ago I was adding email messaging to - a waste-reducing app that connects people with kitchen scraps to their composting neighbours. It turned out to be a tad bit trickier than originally expected. You see, I started with the simplest thing: a "click here to reply" link in the emails. Naturally, it turned a lot of

TypeScript Conditional Imports And Reference Elision

ES6 modules specification explicitly states import/export statements may only be used at the top level of files. Static imports like this bring about a number of benefits such as first-class support for circular dependencies between modules and (potential) support for macros but it also means you cannot conditionally import modules. Which can be a fairly big issue if you're