3 ms·
tldr: A method that is typed as returning `never` either never returns (infinite while/for loop) or throws an error. And as return types can also be conditional
by sod 5y ago
tldr: A method that is typed as returning `never` either never returns (infinite while/for loop) or throws an error. And as return types can also be conditional, your given inputs may switch the return to `never`, allowing typescript to tell you that code following that line will never be executed.
- city41 5y agoThis is only one use case for never. The article goes into a lot more than this. For example using never to create derived types is pretty common.