In this video, we're going to start writing out some code to get a better understanding of how interfaces
work, you'll notice them back inside my code editor and inside of my project directory, I'm going
to make a new file called Interfaces Dots.
All right, so inside of here, we're not going to write out an interface just yet.
Instead, I first want to define an object that represents a car.
We're then going to write a function that kind of operates on that object and we'll start to introduce
interfaces.
So to get started, I'm going to make a variable called Old Civic.
Just a civic is a type of car or like a vehicle of sorts, so it's a Honda Civic by saying old Civic,
I just mean to indicate that we are going to make an object that represents a civic that was made many
years ago.
So inside this object, I'm going to add a couple of different properties to describe exactly some things
about the Civic.
So I'm going to give it a model property, actually.
Well, let's give it a name instead.
That's just a little bit more clear.
So this car is going to have a name of civic aisle, then give it a year that it was built of 2000 and
then a broken property to describe whether or not this vehicle still runs.
I'll say it's broken.
True.
Now that we've put that object together, I want to try creating a function that's going to take in
this object and just print out some different properties about it.
So I'm going to define a function called print vehicle.
Then I'm going to add in a single argument, so we want to call this function with a car, I'm going
to refer to this argument has how about just like a vehicle that makes sense?
And then remember, we need to add in a type annotation to describe exactly what properties or what
type vehicle is right now.
If I hover over a vehicle, it says that it is of type any remember, we want to avoid any types inside
of application.
And we saw how to add in a annotation for an object inside of a function just a moment ago.
So we're going to put in the set of curly braces or something, a colon right there, and then a set
of curly braces.
And then we'll list out all the different properties that we expect this argument to have.
And they're different types.
So I expect a vehicle to have a name that is a string.
I remember inside this type invitation to separate different properties will place a set of a semicolon
like so.
I didn't expect a vehicle to have a year that is a no.
I'm going to zoom out for a second so you can see this whole line.
And I expect a vehicle to have a broken flag that is going to be a boolean.
Finally, I'm going to add in a type invitation to the return of this function, so right after the
argument list, I'll put in a Colen, I don't expect this function to return anything.
So I'm going to give it a type invitation, avoid void like.
So remember, void means our function returns nothing.
All right, I'm going to zoom back in.
So now inside of here, we can do our actual implementation, so I'll just do a couple of console logs
using properties from the vehicle, I'm going to use an E 2015 template string, so I'm going to use
some tactics here.
I'll do some things like let's say, how about name and I'll do vehicle name.
I'll do another little statement here, I'll do something like yea.
The Hickel year.
And then one more for the broken flag as well.
So broken.
No typo there and there we go, vehicle broken.
Cool.
So now we should be able to call print vehicle and pass in old civic old civic structure is a name that
is string year, that is a number and broken.
That is a boolean.
And so that meets the type annotation we just put on that argument right there.
So we should be able to pass an old civic and not have an issue.
So I'm going to take a print vehicle and pass in old civic and everything looks good to me.
Perfect.
All right.
Now I say perfect, but maybe not quite perfect.
There's one little issue inside this file right now, so I bet you can guess what it is.
This type of notation right here is really long.
It's kind of hard to read.
And if we had any more properties on this object, the type of notation would become even harder to
read.
In addition, if we added in more functions that expected to be we expected to call with old Civic,
we would then be duplicating this type annotation for each of those different functions.
And so we would have this really long annotation right here, duplicated several times throughout this
file.
So as you might imagine, yeah, that's probably not the best.
So let's take a quick pause right here.
We're going to come back to the next video and figure out how we can improve this file by using an interface.