Creating Read-only Properties
Here we have an updateUser
function which accepts a user
of type User
.
The User
type has three properties: id
, name
, and age
.
Inside the updateUser
function, our goal is to allow modifications to the name
and age
properties, while ensuring that the id
remains constant and c
Transcript
00:00 Let's say that we have an update user function which takes in a user of type user. Now, this type user has three properties, ID, name, and age. And inside the update user function, we want to be able to modify the name and the age, but we don't want to be able to modify the ID. The ID should always stay static.
00:18 Your job is to work out how to change this type definition of user to give ID a read-only attribute. Good luck.