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 an overview of the subject.
We're then going to talk about why we care about each feature.
In some cases we're gonna discuss features in typescript that I really don't think you're gonna use
that often.
And so I want to kind of make that clear.
You know I want you to understand why do we care about these features and like how often will you actually
use them.
After that we'll then take a look at some different examples inside of our code.
Ed 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 gonna be a little bit quick and it will really be in some 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 boolean is no 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 has a type and so on.
Let's now break down the first part of the statement.
What does what do I mean by an easy way to refer to the different properties and functions.
Well to answer that maybe you'll 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 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 can cut 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 can cat and includes an index
of and so on that would be super inconvenient.
So instead as a shortcut to describe what property is in function this thing has you summarize it in
a single word.
You tell me this is a string so when we referred to that 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 can be really obvious like in the case of the 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 application and that types name was to do.
So there are two ways that I could have referred to this response debt data thing right here.
I could have either told you.
Oh yes.
Response not data is an object that has an I.D. 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 dot data is a to do and instantly you understand what response dot data is.
It is an object that has an I.T. title and completed property okay.
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 for 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 okay.
So let's take a quick pause right here.
We're gonna come back the next video and start to expand on types just a little bit more.