Answer the question
In order to leave comments, you need to log in
How to specify the type of an object?
I have a variable defined like this: public headerUser: IHeaderStaff | IHeaderPupil;
Where interfaces are declared:
export interface IHeaderPupil {
photo: string;
fullname: string;
school: string;
class: string;
formmaster: string;
schools: string;
}
export interface IHeaderStaff {
photo: string;
fullname: string;
school: string;
}
public static getFactory(profile: ProfileBase, i18nService: I18nService): IHeaderPupil | IHeaderStaff {
if (profile instanceof PrincipalProfile) {
return {
'photo': profile.getPhoto(),
'fullname': profile.getName(true),
'school': profile.getOrganizationName(Helper.currentLanguage(i18nService)),
'schools': profile.getName()
};
} else if (profile instanceof PupilProfile) {
return {
'photo': profile.getPhoto(),
'fullname': profile.getName(true),
'school': profile.getOrganizationName(Helper.currentLanguage(i18nService)),
'class': profile.getName(),
'formmaster': profile.getName(),
'schools': profile.getName()
};
} else if (profile instanceof StaffProfile) {
return {
'photo': profile.getPhoto(),
'fullname': profile.getName(true),
'school': profile.getOrganizationName(Helper.currentLanguage(i18nService))
};
}
return null;
}
public headerUser: IHeaderStaff | IHeaderPupil;
this.headerUser = this.userService.header();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question