Essential Types And Notations 20 exercises

Typing Object Literals

Here we have a similar concatName function, except this time it accepts a user object with first and last keys:

const concatName = (user) => {
// squiggly line under `user`
return `${user.first} ${user.last}`;

The test expects that the full name should be returned,

Loading exercise


00:00 In this exercise, we're concatenating a name again, except we are using an object to pass into concatName. User here, it currently doesn't have a type annotation. But based off the implementation below, we can see that it's expecting a first property and a last property on that user object.

00:18 We can see down here inside the tests, the concatName when you pass first John, last Doe, then it works and you get John Doe out of it, and it's also expecting the result to be a string, which it currently is too. So your job is to work out how we can type an object here,

00:36 and specifically this first property is a string, and the last property is a string too. Good luck.