Looking for guidance on creating a new instance in TypeScript. I seem to have everything set up correctly, but encountering an issue.
export class User implements IUser {
public id: number;
public username: string;
public firstname: string;
public lastname: string;
public birthday: string;
public email: string;
public constructor(iUser: IUser)
{
this.id = iUser.id;
this.username = iUser.username;
this.firstname = iUser.firstname;
this.lastname = iUser.lastname;
this.birthday = iUser.birthday;
this.email = iUser.email;
}
}
interface IUser {
id?: number;
username: string;
firstname: string;
lastname: string;
birthday: string;
email: string;
}
Additionally, here is the student class that extends user:
export class Student extends User implements IStudent, IUser {
public indeks: string;
public studyProgram: StudyProgram;
public constructor(iUser: IUser, iStudent: IStudent)
{
super(iUser);
this.indeks = iStudent.indeks;
this.studyProgram = iStudent.studyProgram;
}
}
interface IStudent {
indeks: string;
studyProgram: StudyProgram;
}
However, when attempting to create a new instance of student, an error is encountered:
Supplied parameters do not match any signature of call target. this.student = new Student ({ username: '', firstname: '', lastname: '', birthday: '', email: '', indeks: '', studyProgram: new StudyProgram({ name: '', duration: 0, courseType: '' }) });
Furthermore, let's take a look at the StudyProgram
class:
export class StudyProgram implements StudyProgramInterface {
public id: number;
public name: string;
public duration: number;
public courseType: string;
public studentList: Array<Student>;
public constructor(studyProgramCfg: StudyProgramInterface) {
this.id = studyProgramCfg.id;
this.name = studyProgramCfg.name;
this.duration = studyProgramCfg.duration;
this.courseType = studyProgramCfg.courseType;
}
}
interface StudyProgramInterface {
id?: number;
name: string;
duration: number;
courseType: string;
}