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 going to replace no with simply date like so now in order for old Civic to be considered to be a
vehicle, you'll notice that we've got an area down here.
We have to update its definition.
So instead of your being a simple number, I'm going to instead assignment an instance of a date like
so as soon as I do so, that area 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 see 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 area down here as well.
So now it says that we do not have a summer 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 tablets drink here, so I am using tactics.
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 pile again, that air 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 that 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 primitive 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.
A quick pause and I'll see you in just a minute.