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.
[00:00:20] 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.
[00:00:44] 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.
[00:01:11] 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.
[00:01:39] 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.
[00:03:25] 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.
[00:03:51] 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.
[00:04:12] 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.
[00:04:31] 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.
[00:04:53] 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.
[00:05:23] 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 array.map 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.
[00:06:00] 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.
[00:06:32] 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.
[00:06:51] 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.
[00:07:28] 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.