@kikosko

Как корректно переписать эти классы на TypeScript?

Только начал использовать TypeScript помогите переписать мой код и поясните, что не так
class Students {
    public name: string;
    public surname: string;
    public age: number;
}
    constructor(name:string,surname:string,age:number) {
      this.name = name;
      this.surname = surname;
      this.age = age;
    }
   public refactorStudent(name:string, surname:string,age:number):void {
        this.name = typeof name !== 'undefined' ? name : this.name;
        this.surname = typeof surname !== 'undefined' ? surname : this.surname;
        this.age = typeof age !== 'undefined' ? age : this.age;
    }
    public toString():object{} {
        return `\nName: ${this.name}, Surname: ${this.surname} Age: ${this.age}`
    }
class Group{
    public nameGroup: string;
    public course: string;
    public specialization: string;
    public students: array[string,string,number];
    constructor(nameGroup:string,course:string,specialization:string)  {
            this.nameGroup = nameGroup;
            this.course = course;
            this.specialization = specialization;
            this.students = [];
    }
 public refactorInfo(nameGroup:string, course:string,specialization:string) {
        this.nameGroup = typeof nameGroup !== 'undefined' ? nameGroup : this.nameGroup;
        this.course = typeof course !== 'undefined' ? course : this.course;
        this.specialization = typeof specialization !== 'undefined' ? specialization : this.specialization;
    }
  public  addStudent(...students:object{}) {
        this.students.push(...students);
    }
    public toString():object{}{
        return `Name of Group: ${this.nameGroup}; \nCourse: ${this.course}; \nSpecialization: ${this.specialization};\nStudents: ${this.students}`
    }
}
let student1 = new Students("Aladin","Indus", 20);
let student2 = new Students("Allah","Babah", 25);
let student3 = new Students("Krishna","harehare", 23);
let student4 = new Students("Shiva","4Hends", 24);
let student5 = new Students("Zorro","baf", 19);
let student6 = new Students("Barry","Allen", 28);

let Devs = new Group("D-11",4,"Front-end");

Devs.refactorInfo("D-12");
Devs.addStudent(student1,student2,student3,student4,student5,student6);
student1.refactorStudent("Super");
console.log(Devs.toString());
  • Вопрос задан
  • 54 просмотра
Пригласить эксперта
Ответы на вопрос 1
@igorsmi
Full stack web developer
Зачем и что конкретно переписать?
Так вроде всё норм, непонятно только почему метод toString возвращает объект, когда а самом деле он возвращает строку.
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы