...

/

Introduction to Validating Code with Advanced TypeScript

Introduction to Validating Code with Advanced TypeScript

Get an introduction to advanced Typescript.

We'll cover the following...

Throughout this course, we’ve been using TypeScript to make assertions about the structure of our code to make it easier to validate that our code is correct. Now we’re going to focus on features of TypeScript itself that we can use to enhance the typing of our system.

Many JavaScript programs use a lot of code to protect against invalid data being passed around, continually performing null checks or other type checks. We can also use our TypeScript system to make certain kinds of invalid states impossible without using runtime checks.

We can, for example, specify that a certain value can’t be set to null, and then at compile-time, the compiler must be convinced that a null value can’t get there. Some of these techniques are more verbose than plain JavaScript, but the hope is that the extra typing upfront makes the runtime behavior of the code a lot easier to deal with over the long term.

In this chapter, we’re going to look at a few different helpful TypeScript features: union types, ...