Show notes
Hello friends, this is a little bit later than usual but I just wanted to
get this in because I want to do this every weekday. So today I want totalk about TypeScript and in particular map. So I wrote a blog postrecently that talked about converting typescript or fetch a fetchimplemented or calling fetch in a function over to TypeScript because whenyou call fetch the return value from the dot JSON on that response is goingto be any and so you have to explicitly.Give that a type annotation. And anyway, one of the as I was migrating this
code one of the things that I pointed out was that like we were iteratingover some of the values that came back from that response.json call. And inthe process of migrating the code if you just go about it in a certain waybefore you add the type annotation, you'll find that iterating over itrequires that you type that map.Callback function. And so in our example, we had an array of errors that
could come back from this API call and we're going to iterate over thosearray of errors to kind of join them up into a single error. And so theidea in in this example was you would get a implicit error or implicit anyproblem on that map callback function and as a result you had to type thatexplicitly and so I just say okay, well the argument to this is.An object that has a message property. So anytime you are you have a dot
map call on an array and type script is telling you that you have to givean explicit type to the arguments of that callback function. This wouldalso apply to like a filter or any array of any kind.So anytime that callback function requires that you add type annotations.
That is a sign that the array itself is not typed. So you want to skip thewhole typing of that?Callback function and go back to where that arrayitself is defined and make sure that it has a proper type annotation ofsome kind so that you don't have to worry about typing the callback for anarray method.So if you're ever doing a radon map or a radar every or a radar sum or a
radar filter or reduce or any of that and type script is saying, hey, Idon't know what type this is. This isn't implicit any you need to add atype for this function.Don't do that go fix the array first. Hope that's helpful. Take care.

