When updating items inside an array, prefer immutable updates: create a new array and, for the matching item, return a new object with the change. This avoids surprising side effects.
You'll rename a user identified by id without mutating the input array or any existing user objects.
renameUser(users: { id: number; name: string }[], id: number, newName: string): { id: number; name: string }[].renameUser([{ id: 1, name: 'Ada' }], 1, 'Lin') → [{ id: 1, name: 'Lin' }]
renameUser([{ id: 1, name: 'Ada' }], 2, 'Lin') → [{ id: 1, name: 'Ada' }]