K
K
Konstantin2018-07-22 18:55:18
typescript
Konstantin, 2018-07-22 18:55:18

How to overload parent method?

The parent class has a method:

public getDiaryWeekDay(item: ILessons): string {
    const dateObj = Helper.formatDate(Object.keys(item).shift(), 4);
    return dateObj['n'];
  }

In the child class, I want to overload it:
public getDiaryWeekDay(date: string): string {
    return Helper.formatDate(date, 4)['n'];
  }

This throws a method incompatibility error.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rhymmor, 2018-12-03
@Junart1

There is no (explicit) method overloading in javascript, so in typescript it is very truncated, taking into account the capabilities of js.
In your case, you can change the parent method to:

public getDiaryWeekDay(item: ILessons | string): string {
    // придется добавить проверку на то, что item - объект
    const dateObj = Helper.formatDate(Object.keys(item).shift(), 4);
    return dateObj['n'];
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question