In the last video, we got a good solution to our ad markhor issue.
Now, I repeated the same thing and there like five or six times.
Remember, the whole idea here is that we define instructions on how you can be malleable.
So as long as another class has location with allowed to longitude that are numbers, it can be an argument
to add marker.
So take a look at the impact on custom map.
Now, inside a custom map, we no longer have any direct references to user or company.
So that means that these two import statements at the top of the file can be deleted.
So we now have a standalone custom map class that we could very easily reuse on future projects as well.
In fact, if you ever want to show a Google map in the future, save this file like really save this
file, because as long as you have any other object on any other project you work on that satisfies
this interface.
This class is going to work for you.
You can use this exact class right here to show a Google map and then show different markers on it.
All right, so the last thing I want to do inside this file, I'm going to delete that ad company marker
method down here, we don't need this anymore.
Now, last thing I'm going to do is flip back over to index tortillas and we need to fix up the references
to the methods that we deleted.
So add user marker no longer exists.
It's now going to be add marker and same thing for add company marker as well.
That's also going to be add marker.
So notice how TypeScript has no complaints about these two lines of code, remember, here's what's
going on behind the scenes when we tried to pass in user to add marker.
TypeScript is going to take a look at Ad Merker, it's going to see that the argument must be of type
m'appelle.
To be mockable, you have to have a location with the latitude longitude, so behind the scenes typescript
is automatically inspecting what type user is and it's checking to see if user satisfies the matchable
interface.
So TypeScript is going to look at our definition of what a user is that's going to see that user has
a location, a latitude and longitude that are numbers.
And because it has those, it satisfies the m'appelle interface.
So TypeScript has no issue with us whatsoever passing a user into this method because user correctly
implements that interface.
Remember that that comparison of looking at user and making sure it has all the correct properties is
invisible and occurs behind the scenes.
So we do not have to add in any code whatsoever to say, hey, typescript, make sure that user is matchable.
We didn't do anything like that.
We never said anything inside of our user class to say specifically, hey, this thing is supposed to
be makeable.
Never did it.
TypeScript is doing that comparison for us automatically.
We refer to this as an implicit check typescript is implicitly or kind of behind the scenes automatically
making sure that user has the correct properties with the correct types inside of it to be an argument,
to add marker.
All right, so last thing here, I'm going to save inducts.
I'm going to flip back over my browser, refresh and everything still works as expected, perfect.
OK, so this looks pretty good, so we've now seen something really awesome around interfaces, but
we're not done yet.
Let's take a quick pause.
When we come back, the next video, we're going to add in one more feature to this application.
So quick break and I'll see you in just a minute.