1
00:00:00,660 --> 00:00:05,850
In this video, I want to go over two more pieces of syntax around interfaces, so to get started,

2
00:00:05,850 --> 00:00:08,890
I'm going to go down to the vehicle function inside of here.

3
00:00:08,910 --> 00:00:14,460
You'll notice that our implementation now only accesses one property on the vehicle argument.

4
00:00:14,800 --> 00:00:17,450
The only thing we are referencing is these summary property.

5
00:00:18,180 --> 00:00:19,330
So I got a question for you.

6
00:00:19,950 --> 00:00:25,380
We are saying that the argument must be a vehicle and must satisfy this interface is the terminology

7
00:00:25,380 --> 00:00:26,070
we would use.

8
00:00:26,670 --> 00:00:33,690
And we've said earlier that the vehicle must have a name a year broken and the summary function.

9
00:00:34,440 --> 00:00:38,990
However, our function down here is now only accessing the summary property.

10
00:00:39,570 --> 00:00:40,920
So here's the question.

11
00:00:41,190 --> 00:00:45,690
Is it important for us to say that a vehicle must have these properties available?

12
00:00:46,490 --> 00:00:47,620
I don't think it really is.

13
00:00:48,300 --> 00:00:51,120
So what happens if I delete those additional properties?

14
00:00:52,090 --> 00:00:57,160
I can delete them, they go away, and now you'll notice I do not see any errors inside my file.

15
00:00:58,030 --> 00:00:58,810
Why is that?

16
00:00:59,350 --> 00:01:05,110
Well, when I called vehicle right here, we are saying that in order to be passed into this function,

17
00:01:05,260 --> 00:01:08,020
you must satisfy the vehicle interface.

18
00:01:08,830 --> 00:01:13,240
So we pass an old civic and type script behind the scenes, does a quick check for us.

19
00:01:13,240 --> 00:01:17,230
It says, does this object right here satisfied the vehicle interface?

20
00:01:17,860 --> 00:01:22,900
So TypeScript is going to go back to the vehicle interface definition and it says in order to be considered

21
00:01:22,900 --> 00:01:26,890
to be a vehicle, you must have a function called summary that returns a string.

22
00:01:27,670 --> 00:01:34,360
It then looks at the old civic object and it says, OK, does this object have a summary property?

23
00:01:34,630 --> 00:01:36,820
That is a function that returns a string?

24
00:01:37,660 --> 00:01:38,710
Yes, it does.

25
00:01:39,190 --> 00:01:42,640
And that's the only question that gets asked.

26
00:01:43,540 --> 00:01:49,210
It doesn't matter if we have additional properties on old Civic, doesn't matter when TypeScript tries

27
00:01:49,210 --> 00:01:54,520
to decide if old Civic is a vehicle or not, it's not going to say, oh, you've got these extra properties,

28
00:01:54,640 --> 00:01:56,170
sorry, you can't be a vehicle.

29
00:01:56,560 --> 00:02:00,430
It's only going to check to see if it has this list of properties right here.

30
00:02:00,820 --> 00:02:03,140
If it has that list, awesome.

31
00:02:03,160 --> 00:02:05,620
It is qualified to be a vehicle.

32
00:02:06,920 --> 00:02:12,170
So the code we have here still works, but we've got a much more condensed interface definition.

33
00:02:13,810 --> 00:02:15,140
So here's the important thing here.

34
00:02:15,190 --> 00:02:20,020
Something I want to point out as like kind of step two of this little refactor, now that our interface

35
00:02:20,230 --> 00:02:22,810
only has a single function definition in it.

36
00:02:23,080 --> 00:02:26,100
Do you think the name vehicle is really appropriate here?

37
00:02:26,590 --> 00:02:32,260
Like is calling an object that has a summary property, that is a function that returns a string?

38
00:02:32,860 --> 00:02:35,140
Does it really seem appropriate to call that a vehicle?

39
00:02:35,800 --> 00:02:37,250
I would say maybe it doesn't.

40
00:02:37,510 --> 00:02:42,910
Maybe a more appropriate interface or a name for this interface from now be something like, I don't

41
00:02:42,910 --> 00:02:45,590
know, reportable or something like that.

42
00:02:46,150 --> 00:02:51,880
So now we're saying that in order to be considered the type reportable, you must have a function called

43
00:02:51,880 --> 00:02:53,440
summary that returns a string.

44
00:02:54,610 --> 00:02:59,850
And so now to fix up our file here, down here inside a print vehicles, there is no more vehicle types.

45
00:02:59,860 --> 00:03:01,870
I'm going to replace that with reportable.

46
00:03:02,820 --> 00:03:07,410
Now, just to be clear, the word reportable, I'm kind of meaning to say something that is reportable,

47
00:03:07,830 --> 00:03:09,730
has a summary function that returns a string.

48
00:03:10,110 --> 00:03:12,600
So this is like something that can be reported.

49
00:03:14,060 --> 00:03:18,170
All right, so notice how our definition for the interface is now a lot shorter and a little bit more

50
00:03:18,170 --> 00:03:19,520
generic than it was before.

51
00:03:20,980 --> 00:03:25,240
It's now back down inside the print vehicle interface or function down here, I want to just point out

52
00:03:25,240 --> 00:03:26,180
one more thing here.

53
00:03:26,710 --> 00:03:29,170
Notice how we've got a function called print vehicle.

54
00:03:29,660 --> 00:03:34,960
It takes an argument called vehicle, and it refers to that function or that argument inside the function.

55
00:03:35,360 --> 00:03:37,240
But once again, I got a question for you.

56
00:03:37,690 --> 00:03:42,550
Does anything about this function now really seem like it has anything to do with vehicles?

57
00:03:43,380 --> 00:03:44,750
I don't think it really does.

58
00:03:45,340 --> 00:03:50,530
The only thing that this function really does is taken something that can be reported on and then console

59
00:03:50,530 --> 00:03:53,020
log a summary about that thing.

60
00:03:53,800 --> 00:03:56,920
So maybe we should update some of the terminology inside this function.

61
00:03:57,430 --> 00:04:02,170
Maybe instead of an argument called vehicle, we call this something that's called like, I don't know.

62
00:04:03,180 --> 00:04:06,680
Reports about item, and maybe that makes sense.

63
00:04:08,670 --> 00:04:12,840
And then inside our rather than Collins vehicle, I want to call it maybe something a little bit more

64
00:04:12,840 --> 00:04:15,750
appropriate, like print summary or something like that.

65
00:04:16,140 --> 00:04:19,170
I'm going to update the reference down here as well to be simply print summary.

66
00:04:20,720 --> 00:04:25,820
OK, so all we've really done here is kind of pointed out how our interface no longer really has anything

67
00:04:25,820 --> 00:04:30,740
to do specifically with vehicles, and so I just decided to rename it into something a little bit more

68
00:04:30,740 --> 00:04:31,300
generic.

69
00:04:31,850 --> 00:04:33,770
And I did the same thing with the function down here.

70
00:04:34,920 --> 00:04:36,160
So let's take a quick pause right here.

71
00:04:36,180 --> 00:04:40,200
We're going to come back to the next video and we're going to discuss why this was a very significant

72
00:04:40,350 --> 00:04:43,440
factor by adding in just a little bit more code.

73
00:04:43,440 --> 00:04:45,470
So quick pause and we'll see you in just a minute.

