function updateUser(id: number, updates: UpdatedUser) {
const foundUser = users.find(user => user.id === id)
if (!foundUser) {
console.error("User not found!")
return
}
Object.assign(foundUser, updates)
}
// updateUser(1, { username: "new_john_doe" });
// updateUser(4, { role: "contributor" });
function addNewUser(newUser: any): User {
// Create a new variable called `user`, add an `id` property to it
// and spread in all the properties of the `newUser` object. Think
// about how you should set the type for this `user` object.
// Push the new object to the `users` array, and return the object
// from the function at the end
}
// example usage:
addNewUser({ username: "joe_schmoe", role: "member" })
console.log(users)
type User = {
id: number
username: string
role: "member" | "contributor" | "admin"
}
type UpdatedUser = Partial<User>
let nextUserId = 1
const users: User[] = [
{ id: nextUserId++, username: "john_doe", role: "member" },
{ id: nextUserId++, username: "jane_smith", role: "contributor" }
];