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…

DateStr – A Strongly-Typed Date String for TypeScript

Nearly every project I have ever worked on has had to deal with dates in one way or another. For example, there might be a need to generate a report for a specific date range. This would require a user to select a start and end date, which would be sent over the network to an API. The API would use those dates in an SQL query to retrieve the correct results. Read more on DateStr – A Strongly-Typed Date String for TypeScript…

Five Things to Think About When Considering TypeScript

I can’t imagine working on another JavaScript project without TypeScript, and I haven’t heard much talk of teams adopting TypeScript and regretting it. (For every hour you spend on TypeScript overhead, you probably save five hours of tracking down runtime errors.)

Nevertheless, I do think there are some conditions that could make TypeScript less valuable for a particular project or team. In this article, I’m going to talk about the things you ought to consider when weighing whether or not to add TypeScript to your project.  Read more on Five Things to Think About When Considering TypeScript…

Modular, Type-safe Metadata with TypeScript

One of the humps I’ve encountered while learning TypeScript is coming to terms with a core tenet of the language—the type definitions you write only exist at compile time, not at runtime.

I’ve bumped into this a few times. Can I generate a predicate function to test for type compatibility? No—use type guards instead. Can I reflect on the properties of a type at runtime? No—with caveats. It turns out that those caveats matter a lot, and you can do some pretty powerful things with the tools TypeScript does provide. Read more on Modular, Type-safe Metadata with TypeScript…

Typesafe Container Components with React-Redux’s Connect and TypeScript

TypeScript is fantastic—you get feedback as you write your code to (mostly) ensure you’re passing valid arguments to functions and props to components. However, when using the connect function, you may find that you are permitted to pass invalid props or omit required props to components. In this post, I’ll discuss how the issue arises, and how to fix it by typing your calls to connect! Read more on Typesafe Container Components with React-Redux’s Connect and TypeScript…