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…
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…
We’ve been using TypeScript on an Electron project. It’s been a huge win already—a little additional upfront investment gives us more confidence that our code is correct and reduces the chance that it will pass unexpectedly-shaped objects around, a source of many bugs in my past Node applications.
But sometimes, it’s not immediately clear how to type certain kinds of objects. You can, of course, represent these as
any whenever you need to—but any
any you rely on can weaken your code’s quality. Last week, I discovered another way to avoid falling back on that crutch, thanks to the power of TypeScript’s type system.
Read more on Representing Function Properties in TypeScript…
React apps with Redux are built around an immutable state model. Your entire application state is one immutable data structure stored in a single variable. Changes in your application are not made by mutating fields on model objects or controllers, but by deriving new versions of your application state when you make a single change to the previous version.
This approach comes with some huge benefits in tooling and simplicity, but it requires some care.
Read more on Immutable.js Records in TypeScript…
TypeScript 2.0 was recently released
. This version of TypeScript has some new additions that are great for Redux
development in React
: type narrowing for tagged unions.
Read more on Typed Redux Reducers in TypeScript 2.0...