Enforce immutability on object properties
Flow
Easy
Objective
Make the name & id properties immutable using Flow type annotations
Requirements
Modify the
Usertype to make theidandusernameproperties immutable.Make sure that calling
updateUserfunction with modifiedUsertype 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');