Working with Arrays
Let's start looking at a bit more complex type declarations.
We've got a User
type that is similar to what we've had before. We also have a new Post
interface:
interface User { id: number; firstName: string; lastName: string; role: "admin" | "user" | "super-admin"; post
Transcript
0:00 Let's start looking at a bit more complex type declarations here. We've got a User type, which is very similar to what we had before, firstName, lastName, role, id, and we now added some posts to that user. Each post has an id, and it has a title.
0:17 I've got my defaultUser down here, but posts is yelling at me. It's saying type blah-blah blah-blah blah is missing the following properties from type Post, id, title.
0:27 It looks like here that it's expecting a single post, so what I've said to it is...I'm pretty sure it'll be happy if I just get rid of this and put in that. Yeah, it's not yelling at me anymore.
0:38 I want it to represent an array of posts, so your problem is to basically go into the TypeScript docs, work out how you can represent arrays, and come back and fix this type error.