ReturnType under the hood in TypeScript

Example of ReturnType use
Example of ReturnType use

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:

Example of conditional type
Example of conditional type

For functions we need to have as general type as possible to cover all types of functions:

Find a general function
Find a general function

This is useful in conditional types to infer the value:

Solution
Solution

If you interested in test cases, please have a look at Playground 💻

typescript

Alexey Berezin

Senior Software Engineer, UK Global Talent 🇬🇧

The portrait photo of me

Thank you for reading my blog post! If you have any questions, suggestions, or just want to say hi, feel free to reach out in social networks, or via email. I would love to hear from you!

Comments