Show notes
Your friends it's a beautiful day it's Monday and I wanted to share just
something that I discovered while I was working on something just kind ofan interesting workflow that I've come to start to use and that is if youare trying to use something and you don't know what type it requires ratherthan and assuming that it's written in touch script or at least has typedefinitions so like say you're passing a function to an API and some sortof callback, for example, maybe you're on an input in a j in your JSX andyou have an on change in your not sure what type.The event should be or that first argument or you don't even know whether
it accepts arguments or anything so the way that I do this is rather thanopening up the docks and digging around and trying to find how this is tofind out what I'm expected to do here you put in a function that you'repretty confident is going to break the types in some way and so for ourinput on change example, you can just put an inline function in there thattakes a single argument that you type as null or something and then you'regoing to get an error and the error is going to give you.That the last line on the error is going to say that type such and such is
not assignable to type null so in our example. I literally have this pulledup that's where this example came from but in our example it's type changeevent. HTML input event is not assignable to type null, so now you knowthat it's a type change event and if you're not sure where that changeevent is coming from then you can F12 into the unchange prop and it willtake you right to where that is and here I see it's a type change eventhandler is what that type is and if we F12 into that we just keep on F1eventually we're going to.Find that this is typed as an event handler that accepts a change event
input type or type as it's input ultimately this ends up just extendingthis synthetic event and it has one additional property a targetinterestingly that's an event target of the the given element so what wasinteresting about that actually is that that means that the target for achange event is equal to the input or to the current target.I'm guessing so that's interesting anyway, so yeah, that's just kind of a
general tip if you.You're working with something you're not sure what atleast for our function you're passing this function you're not sure whatarguments it should take pass it something that's just bogus that you youdon't know if it's right or you're pretty confident it's wrong and theerror message should give you an idea of what you are actually supposed todo there and you can do the same with the return value as well so likereturn a symbol or something that you're confident will not be what you'resupposed to return and you'll get an error message indicating to you orgiving you an idea of what you should return hope that's useful andinteresting have a wonderful day.
