Hi everyone, how are you today? Hope you all are doing well!
Today I'm going to explain how hell works and why it's important in conditional structures in typescript. Initially the concept is relatively simple, but the implementation makes us question its real reason for use.
First, it is important to note that the use of hell is directly related to ternary conditions in the typescript. But why?
If we can infer T, G will be the result, if not, F will be the result
The purpose of inference is to test whether an inference is possible, see the example:
It turns out that when we use our custom type we will have never as an answer when trying to infer an object with no return.
Take one more example, if S cannot infer in the sentence pattern it will return never.
There is great power when using inference in conjunction with generics and conditional structures in typescript. They are very useful when in recursive conditional structures in typescript.
I tried to show you real use cases from hell and maybe you don't get the theory at first, but if you have any questions just send me a message and I'll be happy to answer.
Top comments (0)