So now did we covered classes.
Let's have a look at interfaces for Dad I'm going to rename the app.
Fall to classes and add a new app Tia's file which they're all through will be compiled to objects.
And in this app to us follow we'll now dive into interfaces.
So what is an interface.
Well in its simplest version an interface describes the structure of an object we can use it to describe
how an object should look like.
Let me show you an example.
We created the interface with the interface keyword which only exists in typescript not in vanilla javascript.
Now let's name it person maybe again just like on a class I started with a capital of character not
a must do but a recommendation and a convention.
And now in there we can define how a person object should look like.
Now unlike a class will not use this as a blueprint however just as a custom type.
We could say so here could say a person should have a name which is of type String and The Age which
is of type number.
So as you can see here I add properties or field definitions where I have the names of the properties
and the types of values which will be stored in there.
What we don't have here are the concrete values.
So we don't have this and if we would try to assign a default value here we would get an error that
an interface can't have an initialize or so we can't just find a structure not the concrete values.
We can also add a method here.
Greed for example.
No justice with properties we don't add the actual method here though.
But just the structure the description so to say how it should look like and to define a method which
a person object should have.
We add the name of the method then parentheses and then the return type.
For example white and in parentheses you could have any arguments you want to have like a phrase which
should be a type.
Again just the name of the argument and then the type and then the return type of the method of course
you don't have to add parameters.
So what can we now do with this person interface.
What's the idea behind it.
While we can now use this to type check an object for example we could have a variable User 1 and let's
say for some reason we don't initialize it immediately we just want to eventually store an object in
there which has this structure.
So then we can assign a type to user one which could be person we can use our interface as a type.
And now when I assign a value to user one it has to be an object because interfaces are used to define
objects and it has to be an object with a name property which must hold a string age property which
must hold a number and a great method which must take a phrase argument and then also return nothing.
So here in does object we can add a name Max for example.
Now here we add the concrete value and it has to be of that type defined up there now separated with
a comma and that's a difference from our interface definition dare we separate our keys our properties
and methods with semicolons.
But down there when we create object justice in vanilla javascript we use a comma then a H and then
all of course degreed method.
Now the great method as you learned has to be a method which takes one parameter phrase which has to
be a string and where I then want to console lock phrase plus let's say some whitespace plus this stored
name.
This could be one implementation of the Greek method.
Now what's in there doesn't matter it's just import that we have as one parameter which is a string
and that we return nothing.
And now this would be a valid user one object because it satisfies this definition of our interface.
So therefore of course we can now for example cold read and say Hi there I am.
And thereafter we should print name.
So if we now are safe that and let it reload we see Hi there I am Max and that's coming from our agreed
method.
So this is an interface it allows us to define the structure of an object we can use it as a type to
type check for objects that must have this structure.