Check out a free preview of the full Intermediate TypeScript, v2 course

The "Course Overview" Lesson is part of the full, Intermediate TypeScript, v2 course featured in this preview video. Here's what you'd learn in this lesson:

Mike provides an overview of the topics that will be covered in the course. Topics such as declaration merging, extreme types, nullish values, ES modules, generics, conditional types, mapped types, and variance over type params are mentioned.


Transcript from the "Course Overview" Lesson

>> Let's talk a little bit about what we are going to cover in this course. The first topic we're going to get in to is declaration merging. When I learned about this concept, which describes how various things kind of stack on top of each other to form importable and exportable symbols.

This changed the way I looked at TypeScript forever, it was sort of where I went from having to memorize a bunch of special case things. And sort of, I knew that A, B and C happened, and I have to remember that they will happen. Once I learned declaration merging, it's almost like I found the core foundational idea that was responsible for all of this behavior.

It's like finding a law of physics that explains a bunch of different observations. So I figured to start with that because for me it was like a mind-blowing thing, and I think it might be for others as well. We'll move on then to talk about extreme types, so, top and bottom types, respectively, describe types that can accept any value, or types that can accept no value at all.

So, we'll talk about, actual top and bottom types, which are both present in TypeScript, as well as almost top and almost bottom types. So if you've ever seen the object type, or the empty object type which is represented by a pair of open and close braces. We'll talk about those and we'll talk about unit types, which are types that can only hold exactly one value, the set that they represent its of size one.

We will then move on to discussing knowledge values, how do we represent values which may or may not be present, how do we handle those values? What are different types we can use, different operators we can use to handle, things that could be absent, or things that indicate they're empty in TypeScript.

It's important to get this right, because this improves the soundness of your code if you can stick to a couple conventions. So, it's true now, and will be true for the next couple of years that the JavaScript ecosystem is moving towards Native ES modules. You may not have seen this or you may have, but you can create files that have an MJS extension now.

And I know we've all been writing for many years JavaScript modules that use the import keyword and the export keyword. And it's true, we're using module syntax there, this has been around since 2015. The big change is that now we're getting to a point where you can take code that looks like that and run it directly in a browser, or directly in Node JS using that MJS extension or there other ways, we'll get into that.

Because we're at this transition point, more important now than ever, it's like knowing how this works, right? Knowing what you're looking at, how to deal with this, as JavaScript sort of moves towards this being the way we write code and we distribute code, right? You'll probably run into situations where you're dealing with legacy stuff that doesn't do that yet, and then modern stuff that's doing this already.

Almost certainly you're gonna have a code base with something in your Node modules folder that is old and something that's very modern. So we're gonna look at how we can manage that, while we're sort of, stepping up to this new way of doing things. So chapter 6, we're gonna pick up where we left off in TypeScript fundamentals, which was the last chapter we went through was generics.

We just started introducing this concept of a type param, making a type that is expressed in terms of a type parameter. We're gonna talk about how we can apply constraints to a type param, which is sort of like a minimum requirement. So you can't just feed it any type, you have to feed it a type that meets the requirement.

And we'll talk about scopes, so type parameters can have scopes just like variables can have scopes. That will let us start to take on conditional types, you can think of this as, if then or if then else for types, or if you wanna think of it kind of the ternary operator.

Where you can use a condition, question mark, expression for true, question mark expression for false, this is kind of what a conditional type is. It kind of seems odd if you've never looked at this before, why would you need an if then for types, but we'll look at how we can model some things that were just not possible.

And make our types more reusable through using this feature. Something that's possible with conditional types is extracting a type parameter out of another type. And we can do this within the condition of the conditional type using the infer keyword. This lets us sort of pluck something out of an existing type that, we may not have access to this inner thing that's within the outer thing, we may only be given this outer thing.

So it's a really important concept, and a really important language feature that lets us transform types. Our second last major topic is going to be mapped types, think of this kind of but for types, maybe we're taking an interface. And then we're producing another interface with the same keys, but different value types for each field on class or each property on an interface.

We're going to return to an example that we started in TypeScript fundamentals before, this was a type registry, where we were building a data layer with a fetch record function. And this led us, based on arguments that we passed to a function have a proper return type. We started the process of kind of solving this problem in TypeScript fundamentals when we were studying type queries, specifically, indexed access types.

We were using this keyword, where we got the the property names have an interface. And after we cover most of the content in this course, we will be set up to sort of finish the job, or we can start to type the values coming out of this function.

And then finally, we're gonna talk about a really interesting concept, it's starting to get into, type theory, the branch of mathematics. Don't worry, I've spent a lot of time making this as relatable as I can make it, but we're gonna talk about variance over type params. So this is covariance, contravariance, by variance and invariance, and TypeScript as of I think version 4.7, so this is kind of a new thing for TypeScript 5, or within the last few releases.

It gives us a way to state, that we wanna operate in a covariant way, or a contravariant way. So we'll learn what those terms mean, we'll learn the TypeScript syntax for that, and I will do my best to make this very easy to understand. With that, let's jump in.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now