Infer the Type of an Array Member
This exercise begins with a makeStatus
function that takes in an array of TStatuses
that extends an array of strings. The statuses are then returned, kind of like an identity function:
const makeStatus = <TStatuses extends string[]>(statuses: TStatuses) => {
return statuses;
};
Transcript
0:00 This exercise is kind of a nasty one, so sorry about this. We have a makeStatus function where we're taking in TStatuses, and it's extending an array of strings here. Our statuses are representing as TStatuses, and we just return them. It's kind of like an identity function but just for a list of statuses basically.
0:23 We're expecting statuses here to be an array of "INFO" or "DEBUG" or "ERROR" or "WARNING", all of the things that we pass in here, but it's not. It's just an array of strings.
0:34 Your job here is to figure out why that's happening, and what you can do here to change it. It's surprisingly small what you need to do. Don't spend too long on this. You don't need any external libraries, don't need any helpers or anything like that. It's just a slight switch around of a couple of pieces.
0:55 Good luck.