Hello again, everyone.
So in this lesson, we're going to talk about interface, so let's get to it.
So normally, as you know, interface does not exist in JavaScript, so creating a type safe structure
is inherently difficult.
We can say that the interfaces and typescript are basically developed to eliminate this difficulty and
we really wouldn't be too far wrong.
We could also say that the interface in typescript is basically a type definition.
So while classes and functions describe the behavior of objects we can think of, interfaces is defining
object types.
Now, if you've worked with languages such as Java and C Sharp before, you're already familiar with
this topic.
But here we've already mentioned that we can collect similar features in one class and then can extend
them to other classes when necessary.
Actually, the interface works similarly.
We can say that there are some differences, and if you want to make it clearer with a simple example,
yes, let's we use the interface keyword to make a definition and then write the name.
So also defined variables as strings, username, password and email.
Now, here I'm writing a simple method that is using this interface and writing console.
And the person has been registered.
So when I call this method, look here.
We see the parameters at once.
So I need to send all parameters in this interface.
And so we've added all parameters, and as you can see, when I add all the parameters, the error display
is gone.
So now I'm changing this variable to optional, so that means I'll put a question mark in here.
So when I delete this parameter, there's no problem.
So now, look, when I change this string value to a number.
We got an error again, because the program warns me that there's no variable of type, no year, we
already know that, but I wanted you to see it again.
So now let's define a class.
So I want to make the difference a little more clear and you'll see why, so I'll prepare a class and
define variables and then after making these definitions, I'll create an object.
And look at this, so I'm only using the name variable for this object, and I'm not going to give any
value to the other variables.
So now I'm writing a method for the class, just like in here.
And when I call this method, I don't get any errors.
Why is that?
Well, I've only to find one variable here, but it's OK for class because while interfaces want to
use all the variables define that is just not the case for classes.
So you see where we're going with it.
If we are to define all variables, we got to use interface.
But if you're not in that situation, we can say that we can use and define class.
So you remember earlier when we were extending the class, well, likewise, we can implement interfaces.
Just use the same logic.
All right, my friends, so we're going to talk about generics in our next lesson.
Hope to see you there.
All right.