Have you ever heard about TypeScript types narrowing? Have you ever seen such an error in your TypeScript code:
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 🙂
In this article, I’m sharing how this can be done 🙂 It will also be useful if you use another testing framework than NUnit, but the examples are based on it.
If you work with a .NET backend that uses JSON.NET for serialization, you might encounter such weird things in the JSON result returned from a controller:
But what you actually want is the real object present there:
After reading this article, you will know how to achieve that 🙂
Continuing the topic of frontend tests with
jest, we’re taking a look at StrykerJS today. Stryker Mutator is one of the most popular tools for mutation testing. We recently struggled with configuring StykerJS to work properly with
jest and TypeScript. I’d like to share our solution to these problems in this article.
If you are using
and you’re looking for how to show their results in TeamCity as follows:
Then this article will help you configure that 🙂
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.