Hello, my name is Mark Nair, and in these lessons you'll learn about complex types, including literal types, enums, tuples, array types, unions, and the key of type, operator. When we say the word type, most often we mean a primitive type, such as a string or a number. At least we do at the beginning. Sometimes though it's a type we create, such as an interface. Let's take a look at a quick type. So this is a username of type string, by now pretty easy. Sometimes though you want a specific value as the type like this. So instead of string now, username is of type Kramer. It's not the value of Kramer because we haven't given it any value or assigned it here with the assignment operator. I roll over username, here I have let username of type Kramer. But what is Kramer, except just a string that I wrote, and you might think, if I need to limit a type to something literal, which this is exactly what that is, a literal type. So from now on, let's say I can't do something like this. I cannot give it a different value, won't work because username says it's not assignable to type Kramer. Even though Jerry is the content, Jerry is not of type Kramer. We don't really know what type Kramer is, we just know that Jerry isn't that. You might be thinking, if I need to limit a type to something literal, why don't I just use a constant? Well, it's a good question, but let's say you need multiple literals and an object. For example, let's take a look at this. Let's get rid of this line, and I'll make a new object called person, and that's really define it. You know what, even before doing that, I'm going to come up here to line one, instead of saying that username, I am actually going to make this a type. The way I'm going to do that is use the keyword type. Now when I make a type, I'm going to capitalize that so I could tell that that is a type and not something else. So down here, name is now up type right here. Okay. So I need to attribute this now to a value. Now here I have my name is of type Kramer because up here username, Kramer. This by the way is called using a type alias. I'm just popping it in here, but it's the same that I had a second ago. All right. I've set up my person with my architecture here, my shape of the object. Now to give it some real information. So let's just take a second to reinforce some of this. I've made a new type here called username. Now that type really has a literal value to it, a literal type of Kramer. That's it. Now I have defined the shape of my object here, I've defined it with my two properties name is of type username, which really is of type Kramer because of this type alias business here, I'm on one. And wearing puppy shirt is of type Boolean. Then I gave it some values here, name, Kramer, comma, wearing puppy shirt, false. I always fall into the problem of forgetting to put my commas in things and you might do that too. If you run into the situation and get an error, it's usually that syntactical problem. And anyway, right here, the only username I can pop in here is Kramer. If I try something else, I will get an error and the error over here says type Elaine is not assignable to type Kramer. Again, what is type Kramer? All it is is a literal type of this string and Elaine is not that. And really the only thing that is that is the string Kramer and you see that on the pop-up. So on the code completion, I get this very helpful Kramer. That's it. So that works okay. But we can extend this type alias to make it a little more than Kramer, but a lot less than other things. And the way we do that is use the pipe symbol. And this will say or. So now I can say the literal type is Kramer or Elaine or George or Jerry. And all of these then are perfectly legitimate to pop in here as the value of name. Let's explore that just a slight little bit. I will come up with my string. There is Elaine. There's George for the G. Jerry, but if I type in P for something like Paul, there is no P. I want to put type in Joanna. All I have is Jerry type in Alita. Well, I can't do that because Alita is not assignable to type username. The only things I could do are the oars in the string, the literal types, the string values I've given right here. So this just means I can put in George and that works perfectly fine. So that's the reason that we give ourselves a little more flexibility on using literal types, even though we are literally giving it the type of just a series of characters, which doesn't have a meaning in a type. But for us, that is the meaning. So our literal type is this content here or this or this or that, and we can alternate or we can use them. So if we just want to have a series of people and we just know it's going to be between those four names and wearing a puffy shirt is the Boolean between those four. That's a perfectly great way of doing it. Thanks for watching. Stay tuned for the next lesson where I'll show you how enum types work in TypeScript.