Identity Functions 5 exercises
Problem

Find the Generic Flow of an Identity Function

Let's look at a real use case for an identity function.

This config object has some routes, as well as some fetchers that are responsible for fetching data based on the route:


export const configObj = {
routes: ["/", "/about", "/contact"],
fetchers: {
// @ts-expect-error

Loading exercise

Transcript

0:00 Let's look at a real use case for an identity function. We have a config object here, and on this config object, we're declaring two things. We have the roots of the config, and then we have some fetchers. These fetchers are basically supposed to be these roots, and then some fetching stuff that happens based on the roots.

0:21 This does not exist. Ideally, this would be erring here because this fetcher does not exist in the roots up here. The idea of this config object is we're supposed to be constraining it to a certain type. That type that we're constraining it to has to have a certain number of roots, and the fetchers have to belong in the roots.

0:44 You don't need to specify all of them, but it does need to exist in the array above. You're going to need to refactor this into an identity function, and that identity function is going to be called makeConfigObject. In that identity func, you're going to need to do a little bit of fiddling around to find the right generic flow to make this logic work. Good luck.