The Weird Parts of TypeScript 13 exercises
Problem

Typing Functions with Object Params

Here we are working with two functions: logId and logName. The logId function logs an id from an object to the console, while logName does the same with a name:

These functions are grouped into an array called loggers:


const logId = (obj: { id: string }) => {
console

Loading exercise

Transcript

00:00 In this exercise, we have a LogID function which takes in an object with an ID name and logs it to the console. Then we do the same thing with LogName here, which logs a name to the console. Then we have an array of loggers, and those array of loggers, they're not a bunch of forestry people,

00:17 they're just an array of LogID and LogName. Then inside our LogAll function, we have an object which is currently untyped, and we say loggers.foreach function, and then we call that function with the object.

00:32 Your job is to work out what type this object inside the LogAll function should be. It's not a trick question, and it's an interesting one if you really think about it, because let's think about the func in this position here, and look at this type signature quite carefully and work out what's going on.

00:51 Good luck.