Qtr No. 213, New Town Yehlanka Indore 454775
Sam, a TypeScript developer is working on creating a registration portal for his college event. He has created a user object as shown below. When he used it to write the logic for further processing, he found that there are redundant code.
Modify the given TypeScript code to remove the redundancy.
let userObj : {userName : string, uid : number | string};
function registerUser(user : {userName : string, uid : number | string}){
user.userName = userObj.userName;
user.uid = userObj.uid;
}
No modification required
let userObj : {userName : string, uid : number | string};
function registerUser(user : {userName : string, uid : number | string}){
user.userName = userObj.userName;
user.uid = userObj.uid;
} //end of the option
type NumOrString = number | string;
let userObj : {userName : string, uid : NumOrString}
function registeruser(user : NumOrString){
user.username = userObj.username;
user.uid = userObj.uid;
} //end of the option
type NumOrString = number | string;
type UserObj = {userName : string, uid : NumOrString};
let userObj : UserObj = {"Samuel", 231};
function registeruser(user : UserObj){
user.username = userObj.username;
user.uid = userObj.uid;
} //end of the option
To get all Infosys Certified TypeScript Developer Exam questions Join Group https://bit.ly/infy_premium_group
We're passionate about offering best placement materials and courses!! A one stop place for Placement Materials. We daily post Offcampus updates and Placement Materials.
Qtr No. 213, New Town Yehlanka Indore 454775
admin@prepflix.in