ReturnType under the hood in TypeScript
19 Apr 2021
We start solving medium challenges today. And we are going to discuss Get Return Type
To get rid of repetitive code we sometimes need to reuse return type of any functions. Let's do that ⤵️
Unwrapping values from types
In Unwrapping the Promises we already discussed that Type inference in conditional types is used to get an inferred type variable in the true branch of the conditional type:
For functions we need to have as general type as possible to cover all types of functions:
This is useful in conditional types to infer the value:
If you interested in test cases, please have a look at Playground 💻
typescript