Enforce immutability on object properties
Flow
Easy
Objective
Make the name & id properties immutable using Flow type annotations
Requirements
Modify the
User
type to make theid
andusername
properties immutable.Make sure that calling
updateUser
function with modifiedUser
type will not throw Flow errors.
Starting code
// @flow
type User = {
id: number,
username: string,
email: string,
};
function updateUser(user: User, newEmail: string) {
user.email = newEmail;
}
const user: User = {
id: 1,
username: 'JohnSmith',
email: 'john.smith@example.com',
};
updateUser(user, 'john.new@example.com');