scrimba
Learn TypeScript
Utility Types & Partial
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

Utility Types & Partial
AboutCommentsNotes
Utility Types & Partial
Expand for more info
index.ts
run
preview
console
type User = {
id: number
username: string
role: "member" | "contributor" | "admin"
}

const users: User[] = [
{ id: 1, username: "john_doe", role: "member" },
{ id: 2, username: "jane_smith", role: "contributor" },
{ id: 3, username: "alice_jones", role: "admin" },
{ id: 4, username: "charlie_brown", role: "member" },
];

function updateUser(id: any, updates: any) {
// Find the user in the array by the id
// Use Object.assign to update the found user in place.
// Check MDN if you need help with using Object.assign
}

// Example updates:
updateUser(1, { username: "new_john_doe" });
updateUser(4, { role: "contributor" });

console.log(users)
Console
/index.html
-7:04