Show notes
https://twitter.com/kentcdodds/status/1381453907730128900?s=20
Hey friends So last night I tweeted this TypeScript question. When have you
used never in a production codebase links to examples welcome? And I failedto mute the conversation and so I ended up waking up the next morning withtons of notifications, which was great. So many people were happy to shareand I just wanted to share with you a couple or the like basic themes ofthe different examples that people shared.So the first is discriminating union. Oh and by the way, if you've never
heard of never before the basic idea is it's a way for you to say.Hey thetype script type checker as it's flowing through the types of myapplication, it should never be able to hit this type.So it's like those situations where you like this should never happen.
That's basically when you use never. So anyway, the first is discriminatingunions and a common example for this was if you had a component that couldtake a variety of different props. So an example is a component that couldlike draw a shape so you could be rectangle or a square or a circle anddepending on the type of shape you want to draw you're going.To have different props And so square will have a width Rectangle will also
have a height in addition to that. And then circle won't have either ofthose it'll have like a diameter something. So the you know, thediscriminating union's use case for never would be when you union thoseprops together you want to be able to say hey when it's a circle I neverwant to have a height or a width and when it it's a square.I never want to have a height because I just get it from the width and I
never want to have a diameter because it's not a circle. In mymind,Actually most of the examples were similar to that and in my mind mostof the time you're actually probably better off just making two separatecomponents or yeah different components entirely that are responsible fordoing that specific thing.However, sometimes there are definitely use cases for you know, if if
you're going to provide me this prop, you also must provide me this prop,but if you provide this other one, then you must not provide this thisother. So like aria described by versus already described stuff like that.So that was like the primary use case in addition.Switch out ifs and else
statements this is where you can make a function that is basically theywould call it a certain ever and it would return never it would throw anerror. And basically your time typescript well by calling that function youget a type error.And so if you put this as the default case or something and you're not
handling every case then type script is going to cause a problem for you.And then the last one was conditional types and that one still pretty hazyfor me. I can't really explain it. So anyway, hopefully some of that wasinteresting.And I hope you have a wonderful day. Bye.

