Typescript type error

I’m following the exercise to add a type to the array below but I get a complaint in Typescript with the following:
“Type ‘{ name: string; age: number; occupation: string; }’ is missing the following properties from type ‘User’: name, age”

What am I doing wrong?

type User = {
  name: string
  age: number
  occupation?: string

let users: User = [
  { name: 'John', age: 25, occupation: 'gardener' },
  { name: 'Mary', age: 31, occupation: 'teacher' },

You want to declare that it is an array of User, but you have declared it to just be a User.

let users: User[] = ...
1 Like