How Does TypeScript Types Narrowing Work?

Have you ever heard about TypeScript types narrowing? Have you ever seen such an error in your TypeScript code:

TypeScript complains about "name" property not existing  on "person" object of type "object"

Even tough, you really knew that the name property exists on the person object? How did you solve this problem? Did you cast the variable to the expected type?

If the answer to at least one of those questions is yes, you might read on. There are better ways of determining the type of local variable in TypeScript. What’s more, TS compiler does a lot of stuff for us by leveraging types narrowing. In this article, we are going to see how it works and how it can be useful ?

Migrating JavaScript React App to TypeScript

Featured image of Yumasoft article on migrating JavaScript to TypeScript

In one of our biggest projects, we develop and maintain a React web application. Last year, we decided to migrate it to TypeScript. How did it go? How did we migrate JavaScript to TypeScript? Was it worth it? What struggles we met and are we still having any issues? I’ll try to address these questions in this article.

Disclaimer: I’m not describing the migration process step-by-step or TypeScript itself in this article. You can find many resources on that online, including official TS docs.