Когда пытаюсь скомпилировать код, вижу такую ошибку: "Expected 3 arguments, but got 1" на мутод "refactorStudent" и "refactorInfo", подскажите как пофиксить. Да и вообще, правильно ли я использую TypeScript (только начал).
//constructor for creating students
class Student {
constructor(public name: string, public surname: string, public age: number) {
this.name = name;
this.surname = surname;
this.age = age;
}
//rewrite one or all options of student info
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;
}
//show info about student
public toString(): string {
return `\nName: ${this.name}, Surname: ${this.surname}, Age: ${this.age}`;
}
}
//constructor for create groups with students
class Group {
public students: any[];
constructor(public nameGroup: string, public course: string, public specialization: string) {
this.nameGroup = nameGroup;
this.course = course;
this.specialization = specialization;
this.students = [];
}
//rewrite one or all options of group info
public refactorInfo(nameGroup: string, course: string, specialization: string): void {
this.nameGroup = typeof nameGroup !== 'undefined' ? nameGroup : this.nameGroup;
this.course = typeof course !== 'undefined' ? course : this.course;
this.specialization = typeof specialization !== 'undefined' ?
specialization : this.specialization;
}
//add new student
public addStudent(...students: any[]) {
this.students.push(...students);
}
// show info about group with students
public toString(): string {
return `Name of Group: ${this.nameGroup}; \nCourse: ${this.course}; \nSpecialization:
${this.specialization};\nStudents: ${this.students}`
}
}
// create students
let student1 = new Student("Aladin", "Indus", 20);
let student2 = new Student("Allah", "Babah", 25);
let student3 = new Student("Krishna", "harehare", 23);
// create group
let Devs = new Group("D-11", "4", "Front-end");
//rename group name
Devs.refactorInfo("D-12");
//push students into group
Devs.addStudent(student1, student2, student3);
//rename name of first student
student1.refactorStudent("Super");
console.log(Devs.toString());
Если хочешь чтоб аргумент был не mandatory то добавь "?" как я написал ниже.
public refactorStudent(name?: string, surname?: string, age?: number): void {
// ....
}
Кофе для программистов: как напиток влияет на продуктивность кодеров?
Рекламные вывески: как привлечь внимание и увеличить продажи
Стратегії та тренди в SMM - Технології, що формують майбутнє сьогодні
Выделенный сервер, что это, для чего нужен и какие характеристики важны?
Современные решения для бизнеса: как облачные и виртуальные технологии меняют рынок
У меня есть на входе объект, как вернуть на выходе измененный объект на основе сущствующего?
Скиньте пожалуйста самый простой пример с двумя input, в которых будут обновляться координаты мышки по горизонтали и вертикалиБез jQuery , спасибо...