I have a Type described in typescript like this -
export type User = {
  name: string;
  username: string;
  phoneNumber: string;
  personalEmail?: string;
  workEmail?: string
}
I'm fetching some data from a json file which consists of objects like these and shaping the data to this type User for each object with this function
const shaper = (obj: any): User {
  const user: User = {
    name: obj.name,
    username: obj.username,
    number: obj.number,
    personalEmail: obj.personalEmail,
    workEmail: obj.workEmail,
  }
 // remove from user the fields which have value === undefined
  return user;
}
In the shaper function, I want to remove the fields of the variable user which have the value as undefined (eg : obj.personalEmail does not exist)
How do I achieve this?
 
     
    