In this video I want to add in a couple little notes around syntax of interfaces.
So once again when we define an interface we're going to list out all the different property names and
types that we expect something that is a vehicle to have.
We are not only limited to expressing primitive values inside of here we can instead express any different
type.
We want to inside of an interface.
So for example let's say instead of the year property being a number we instead want this to be a more
complex object like an instance of a date to do so I'm gonna replace no with simply date like so now
in order for old Civic to be considered to be a vehicle in those so we've got an error down here.
We have to update its definition.
So instead of your being a simple No I'm going to instead assign it an instance of a date like so as
soon as I do so that error down here goes away.
So once again we are not limited to just basic values or primitive values inside of an interface definition
we can assign any type inside there that we want that also includes functions.
So let's say that we want to say that in order for old Civic to be considered to be a vehicle we want
it to also have a function called summary.
So in other words I want this object right here to have a property or a function called summary.
And if we call it maybe it should return a String that summarizes some different facts about the vehicle
to express that I'm going to add in another property on vehicle called summary like so and then instead
of immediately putting in a set or a comma or C a colon right there I'll put in a set of parentheses
and then a colon right after it and I'm going to label what I would expect the summary function to return.
So in this case maybe it's going to return a String that summarizes some different facts about the car
so this right here says that anything that wants to be a vehicle has to have a function called summary
that returns a string if we then go back down to the bottom again you'll notice we have an error down
here as well.
So now it says that we do not have a summary property inside of old civic.
So to fix this up we would have to add in a summary function that satisfies this type right here.
So it has to be a function with no arguments that returns a string.
And so we can add it on like so.
So now to return some information about this vehicle we could return about like name is this name like
so and again notice the yes 2015 template string here so I am using back tax.
So now that my object has a summary function that returns a string it once again qualifies as being
a vehicle so if I go back down to the bottom of the file again that era has now gone away and now inside
of my print vehicle function rather than trying to pull off all these different properties one by one
I can instead rely upon that summary function so I can call something like console dot log vehicle dot
summary like so
all right.
So again just two notes here.
First off we can use any type inside of our interface definition we want.
We are not limited just to permanent values.
Second important note is that inside of our interface definition we can express functions inside there
as well so let's take a quick pause right here in the next video.
I want to share two more important notes with you around basic syntax of interfaces so quick pause and
I'll see you in just a minute.