BRIEFS logo BRIEFS

Use TypeScript any/unknown/casting when you're getting started

01/18/2021 , 2m, 54s

Hey there friends. So today I wanted to talk about TypeScript again, and I want to talk about adopting TypeScript. So when I first started into TypeScript I was working. I I'd been doing flow for a long time and then I switched over to TypeScript. This is at PayPal. And one of the first projects that I used TypeScript in was this project called PP React, which is short for PayPal React.

It was a component library. And I I was working with a lot of abstractions as my first and my first foray.Into TypeScript and when you work with abstractions sometimes you the typings for those things can be a little bit more complicated than when you're just like doing everyday consuming of abstractions or calling functions or making reactant components or whatever.

And so it was a little bit more challenging but then I made it even more challenging because I tried to make an abstraction for some of the the components that I was using that was a higher order component and if you have experience with types and higher order components, you know that it's just really hard.

It's a disaster. So anyway, I was,Doing this and I developed this opinion where I'd say, you know, what I think that it's better. And I actually ended up giving up on the HOC. It didn't really add a whole lot of value anyway. But I developed this opinion where I think that it's better when you're just barely adopting a typed language or you know, something like that.

Yeah, basically when you're adopting TypeScript, it's you're you're better off focusing on getting like not focusing on getting everything perfect. So, you don't want to enable strict.Type checking right from the get-go You're really bad at TypeScript when you're just barely getting started. And so it's way better if you just embrace that fact and say I'm going to use any or I'm going to use unknown as my argument type here.

And I'm joined I'm going to cast all the types all over the place and whatever. And maybe you're not getting all the value out of the type system that you can you you aren't when you do that. But you're not going to be spending so much time trying to make the types perfect with your imperfect knowledge of TypeScript that