Flavoring: Flexible Nominal Typing for TypeScript

Recently, we’ve been making heavy use of TypeScript at Atomic Object. We love the great tooling and instant feedback we get with the language’s powerful type system. TypeScript’s structural type system gives us a lot of powerful tools for making invalid states unrepresentable, thereby pointing out bugs at compile time instead of runtime.

However, one challenge we’ve faced with TypeScript in applying this approach is how to differentiate between values that have the same shape, but mean very different things. For example, if both my Person and my BlogPost have a numeric ID, I’d really like to communicate to TypeScript that they’re not interchangeable. But a function that takes a number accepts both kinds of values.

This post will examine the challenges one might face using the usual approach to this modeling problem, and how we’ve side-stepped them with a variation on the usual technique.
Read more on Flavoring: Flexible Nominal Typing for TypeScript…

Three Tips for Migrating from JavaScript to TypeScript

Over time, and especially in the past few years, the tech community has gotten sick of JavaScript and its loose typing. Trying to write a complicated program without static types is like driving at night without headlights—you’ll probably be fine for a while, but there’s a good chance you’ll crash a few times along the way. Read more on Three Tips for Migrating from JavaScript to TypeScript…

Understanding and Embracing TypeScript’s “readonly”

If you’ve tried to use JavaScript in a functional style, you’ve no doubt chafed at the fact that all those little objects flying around at any given time are about as far as they can possibly get from immutable. You can, of course, be careful to write code that never mutates an object, but while good practices improve your code, they’re weak defenses against bugs.

TypeScript can help you with its readonly property modifier. With readonly, you can rely on TypeScript’s static analysis to enforce and flag mutations in your codebase.
Read more on Understanding and Embracing TypeScript’s “readonly”…

A New Redux Action Pattern for TypeScript 2.4+

In September 2016, I wrote a post about a pattern for strongly typed Redux reducers in TypeScript. Since then, the TypeScript team has been busy enhancing the language, and recent changes in TypeScript have enabled a much more natural, boilerplate-free pattern for strongly typed actions and reducers in TypeScript.
Read more on A New Redux Action Pattern for TypeScript 2.4+…

Making Toast from Scratch in React-Redux

Getting UI elements for free is a good feeling. When it comes to popup notifications, other frameworks provide these components for free. For instance, Rails has flashes and Android has snackbars. React is a moving target, so pulling in external libraries can help simplify situations, but it may prevent extensibility later.
Read more on Making Toast from Scratch in React-Redux…