You cannot extend HTMLDivElement because it is not declared as a class. This makes sense because the main native type does not make sense to expand.
You have two alternative options.
Option 1: Implements!
Since HTMLDivElement is an interface, you can implement it ...
class QuizElement implements HTMLDivElement {
You will need to implement all the properties and methods of the interface. You probably don't want to do this.
Option 2: Delegation.
You can provide specific properties and methods that you want to make available in your QuizElement class, and then delegate the actual instance of HTMLDivElement . A quick example below:
class QuizElement { private element: HTMLDivElement; constructor(id: string) { this.element = <HTMLDivElement>document.getElementById(id); } set innerHTML(content: string) { this.element.innerHTML = content; } } var quizElement = new QuizElement('quiz'); quizElement.innerHTML = 'Example';
Fenton
source share