3 Minutes With Kent

When to use TypeScript's `never` type

Informações:

Synopsis

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 failed to mute the conversation and so I ended up waking up the next morning with tons of notifications, which was great. So many people were happy to share and I just wanted to share with you a couple or the like basic themes of the 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 the type script type checker as it's flowing through the types of my application, 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 discriminating unions and a common example for this was if you had a component that could take a variety of different props. So an example is a