I am create a small application in typescript, where I am using interfaces to
create objects of specific types like the following UserProfile interface.
both the interface and the fulfill function are defined in user-profile.ts file.
export interface UserProfile {
readonly titel_id: number;
readonly user_name: string;
readonly email: string;
readonly first_name: string;
readonly last_name: string;
readonly phone: string;
readonly fax: string;
}
export function fulfill({ titel_id, user_name, email, first_name, last_name, phone, fax }: any): UserProfile {
return {
titel_id,
user_name,
email,
first_name,
last_name,
phone,
fax
}
}
I am calling this function from my UserMdoel's find function which contains all the fields of user table and fulfill function gives only those fields which are speficied in interface. But as you can see that I have to write the fields 3 times
once in interface, then in object destructring and then in return statement. It means if I later have to change the fields I have to change this on 3 places.
Is there a better way to solve this issue?
let profile: UserProfile = <UserProfile> object;