Inference Basics 6 exercises
Problem

Get the Return Type of a Function

In this exercise, we have a function called myFunc which we can see returns a string when hovering over the name:


// From the hover popup
// const myFunc: () => string
const myFunc = () => {
return "hello"
}

We want to somehow take the knowledge of what myFunc returns and stick i

Loading exercise

Transcript

0:00 In this exercise, we have a function called myFunc, which we can see returns a string here. If we hover over it, we can see it's returning a string.

0:09 What we want to do is somehow take that knowledge of what this function returns and stick it inside MyFuncReturn. We need to change this unknown to somehow be a string. Of course, we could just type this out, but then if this changes then it's not going to be the same anymore.

0:25 What we want to do is extract the information, the ReturnType from myFunc into this type. What you'll need is some TS utility types and probably also the type of operator. Good luck.