5. Interfaces and Inheritance
Activity 5.01: Building a User Management Component Using Interfaces
Solution:
- Create a user object interface with the following properties:
email : string
,loginAt : number
, andtoken : string
. MakeloginAt
andtoken
optional:interface UserObj { email: string loginAt?: number token?: string }
- Build a class interface with a global property user and use the interface created in Step 1 to apply user object rules. You need to define a
getUser
method that returns the user object. Use the interface to ensure that the return object is a user object. Finally, define alogin
method that takes auser
object andpassword(type string)
as arguments. Use the user object interface as theuser
argument type:interface UserClass { user: UserObj getUser(): UserObj login(user: UserObj, password: string):UserObj...