Type Transformations Workshop (9 exercises)
Problem

Extract the Result From Several Possible Functions

Here are a few different examples of what a parser can be.

The first is an object with a key of parse that is a function that returns a number:

This parser is a function returns a string:

Finally, this parser is object with a key of extract that is a function that returns a boolean:

Challenge

Your challenge is to write a type helper that can take in any of the above parsers, and extract the result.

Transcript

[0:00] In this exercise, we have several different understandings of what a parser can be. Here, it's an object with a key called parse which has a function which returns a number. Here, it's just a function that returns a string. Here, it's an object with extract which has a function that returns a Boolean.
[0:20] Now, what your job is is to get the parser result where T can be any one of these things. We could parse in typeof parser1 and get back a number. We get typeof parser2 and get back a string. Typeof parser3, get back a Boolean.

[0:37] Each time we're trying to extract the element from here. That's your job, is to try and work out how to express getparser results so that you can parse in any one of these and you'll still be able to infer the thing that's being grabbed.