In this video, we're going to start to cover our first big topic, which is basic types in TypeScript
for every topic that we go through, here's the game plan we're going to try to follow.
First off, we're going to get a plain definition and overview of the subject.
We're then going to talk about why we care about each feature.
In some cases, we're going to discuss features in typescript that I really don't think you're going
to use that often.
And so I want to kind of make that clear.
I want you to understand why do we care about these features and how often will you actually use them
after that?
Will then take a look at some different examples inside of our code editor by actually writing out some
code.
And then finally, we'll close every topic out with a discussion of when to use it.
Sometimes when to use it is going to be a little bit quick and it will really be in some of the applications
we put together that you're going to discover when we use some of these different features.
OK, so that's a flow we're going to go through, like I said, our first topic is going to be basic
types.
So let's get to it.
Let's begin with a plain definition or as plain as I can make it.
Now, I'm sure if you open up a dictionary, you're going to find a very academic definition of what
a type is.
But if I had to use my own words to describe what a type is, here's what I would say.
I would say that in typescript, a type is an easy way to refer to the different properties and functions
that a value has.
And there's a lot of meaning in the statement right here, so let's kind of break it apart piece by
piece.
First off, what is a value?
Well, a value in JavaScript and TypeScript, is anything that we can assign to a variable.
So what can we assign to variables?
Well, we can assign strings, numbers, booleans, null, undefined objects, functions, classes,
arrays and so on.
So all of those different things have types in array, has a type A object has a type.
A function has a type, A class as a type and so on.
So let's now break down the first part of the statement, what is what do I mean by an easy way to refer
to the different properties and functions?
Well, the answer that maybe would be easier to take a look at a quick diagram.
All right, so in this diagram right here, I want you to take a look at this box right here, and I
want you to answer a question for me.
Here's the question.
What is inside that box like?
What is in there?
I think you can probably give me two answers.
Maybe one would be to simply say it is a string.
Alternatively, if you wanted to give me a more detailed answer, you might say is a value that has
all the properties and methods that we assume that a string has.
So to really understand that part, I think we would really need to understand what different properties
and methods a string has.
Here's a short list of just some of the functions that belong to a string in JavaScript.
So every string in JavaScript has access to the character at function and concat and includes an index
of and so on.
If I had to tell you what this thing is right here, by listing out all the different functions that
belong to it, that would be really inconvenient.
In other words, if I asked you what is inside this box and you responded to me, oh, yeah, Steven,
that is a value that has the function character at and concat and includes an index of and so on that
would be super inconvenient.
So instead, as a shortcut to describe what property is and function this thing has, you summarize
it in a single word.
You tell me this is a string.
So when we referred to the type of a value, it is a shortcut to refer to the different methods and
properties that that value has.
Every value that we create has a type assigned to it, in some cases, that type is going to be really
obvious, like in the case of this string right here.
However, in some other cases, we're going to learn that types exist that are tied to values that you
kind of wouldn't expect.
So, for example, let's take a quick glance at that application we just worked on a moment ago.
Remember, inside of here, we created an interface called to do.
When we created this interface, we created a new type inside of our application and that type of name
was to do so.
There are two ways that I could have referred to this response data thing right here.
I could have either told you, oh, yes, response not data is an object that has an ID property, a
title property and a completed property.
But if I had to repeat that statement every single time you asked me what this variable was, it would
be just really inconvenient.
So instead, we formed a shortcut.
Instead, I can say response data is a to do.
And instantly you understand what response DOT data is.
It is an object that has an ID title and completed property.
OK, so to sum up here, the big takeaway is that when we start to discuss types in TypeScript, these
are just shortcuts.
They are labels.
We're describing the different properties and method methods that a single value has.
And then the secondary statement to that is that every value in typescript has a type, every single
one of them.
OK, so let's take a quick pause right here.
We're going to come back to the next video and start to expand on type's just a little bit more.