This course has been updated! We now recommend you take the Intermediate React, v5 course.
Transcript from the "Typing an Error Boundary" Lesson
[00:00:00]
>> Brian Holt: Let's go do error boundary. So rename ErrorBoundary.tsx.
>> Brian Holt: And hopefully you're sensing a pattern here that I just renamed the file, and I just fixed the problems. And that's just kind of the process here. I helped to migrate one a the code bases at LinkedIn to be in typescript, and that's literally what I did for a month.
[00:00:26] That's just rename files and fix it. And ask people, what the hell were you doing? Or thinking? That's kind of my job in general. So, I'm gonna move this from being on a constructor to being a public class property. Again you totally could just do it like this, and you could pass in what the state is, but I like doing it as public class properties better.
[00:00:53] So I'm just going to delete that, and move that outside of the constructor, and delete the constructor.
>> Brian Holt: And then we're gonna say this is a public state. We're gonna say this is a public static, public, public and public.
>> Brian Holt: We have to tell it that errors are indeed errors, and the info is ErrorInfo.
[00:01:32]
>> Brian Holt: And that's it. Everything else it can figure out what it is.
>> Brian Holt: Great, any questions? That was pretty easy.
>> Brian Holt: I think that's what you'll find as well. So, this is what I tell people that wanna move to typescript. I actually have a really great tweet that I'll show you later, that migrating the typescript is so painful, and you're just questioning, why did I subject myself to this torture?
[00:02:04] Until you get to about 60% of your code's base being in typescript, and then all of a sudden, everything is magical. All of a sudden, this was a fantastic idea and you're a genius. [LAUGH] That's kind of the story of my life. I just kinda go up and down like I'm an idiot.
[00:02:19] And then I'm a genius, but mostly the idiot park. Anyway, this is not therapy with Brian. What I wanna say though, is there's gonna be parts of this where you're gonna wonder why did I choose to do this to myself? And the payoff really comes once, most of your code bases in typescript because then your code base will start kind of coalescing into like coherence, I suppose.
[00:02:42] And, it'll be nice like you can just import a file from another team, and you can see all the types in it, and old type check all that stuff. It all makes sense. So, yeah. That's what I would say, just be patient a little bit. Cuz you have to get through a lot of it before it starts making any sense.