total-typescript/beginners-typescript-tutorial

Exercise 08 can be solved without a `User` return type annotation

with-heart opened this issue · 1 comments

Providing a default user that matches the shape of User without actually providing a return type annotation passes the tests and typecheck, but that obviously avoids the intended lesson.

const makeUser = () => {
  return {
    id: 1,
    firstName: '',
    lastName: '',
    role: 'user',
    posts: [
      {
        id: 1,
        title: '',
      },
    ],
  }
}

You'll notice that that is actually one of the valid solutions (solution 2)! My point here (which is hard to grok without accompanying videos) is that you don't need to annotate the return type of functions.