Transcript from the "Adding Types" Lesson
[00:00:23] There's no effort to define whether the structure of an object is equivalent to the structure of another object.
>> Mike North: So one of the things we hope that types will help us do is take some run time errors and move them upstream into compile time errors. This is always a good thing.
[00:00:37] You'll always want to be the one that catches the error on the devbox, not to get a bug report from your user. Types serve as the basis for excellent documentation to your fellow developers. So has anyone here tried to write a Webpack configuration? Right, so it's a pretty involved object, is it not?
[00:01:19] And we have upfront defined the valid properties you can define and the valid types of values that those things can have and as a result, that is right there, right in your editor. It's not something that you have to go flip back and forth between documentation and code form.
[00:03:00] We can only do so much, we're humans, right, we can only remember so much. We can only keep so much straight, and these are not training wheels, these are tools for kind of taking on more ambitious challenges, and being able to get past that point where. And I think we've all been there or we all will be there one day, but that point where things are so complex that a project is basically starting to collapse under its own weight or under its own complexity.
[00:04:03] So, if we just to give you a sneak pick here, I don't think we'll talk about this in too much depth, but the idea of how Chrome works under the hood is there an interpreter and a compiler. The interpreter starts running your code, right? Runs, say a function that you've defined.
[00:04:27] And if you are very consistent about the way you use that function and you start to use it over and over and over and over again. Chrome will say, well hey, we've got some information about the use of this function. And it seems that the same number of arguments are being passed in, the types of those arguments are the same, I wonder if we could start to kind of optimize this a bit.
[00:05:21] So if you, the term a lot of people use here is that function just became hot code. Meaning it's running fast and it's in this optimized mode. As soon as you mess with the types, as soon as you break the rules of the strongly typed world, that code goes back into slow mode again.
[00:05:44] So Typescript gives us some constraints that help us get into that hot mode and stay there.