Rozširovanie rozhraní v OOP v TypeScript

Rozhrania v TypeScript môžu dediť jeden od druhého. Takáto interakcia sa nazýva rozširovanie rozhraní. Pozrime sa na príklad. Nech máme rozhranie ISize:

typescriptinterface ISize {
  height: number;
  width: number;
}

Vytvorme rozhranie IStyle, ktoré rozširuje ISize:

typescriptinterface IStyle extends ISize {
  color: string;
}

Teraz vytvorme triedu Figure, ktorá implementuje rozhranie IStyle. Naša trieda bude musieť implementovať ako vlastnosť samotného rozhrania, tak aj jeho rodiča. Urobme to:

typescriptclass Figure implements IStyle {
  height: number;
  width: number;
  color: string;
  
  constructor(height: number, width: number, color: string) {
    this.height = height;
    this.width  = width;
    this.color  = color;
  }
}

Skontrolujme fungovanie:

typescriptlet fig = new Figure(130, 200, 'green');
console.log(fig);
Задание 1

Vytvorte rozhranie IProgrammer s vlastnosťami salary a language. Nech toto rozhranie dedí od IUser s vlastnosťami name, birthday.

Задание 2

Vytvorte triedu Employee, ktorá implementuje IProgrammer.