ReturnType under the hood

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

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

Find a general function

This is useful in conditional types to infer the value:

Solution

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

typescriptmedium

Let's chat and have fun 🧑‍💻👩‍💻

No more often than once a week I write 📄 about TypeScript 💪, video playback 📺 and frontend related topics. You can unsubscribe in any time ↘️