In the default TypeScript HTML app from visual studio, I added
HTMLElement
to the first line of the window.onload event handler, thinking that I could provide a type for "el".
thus:
class Greeter {
element: HTMLElement;
span: HTMLElement;
timerToken: number;
constructor (element: HTMLElement) {
this.element = element;
this.element.innerText += "The time is: ";
this.span = document.createElement('span');
this.element.appendChild(this.span);
this.span.innerText = new Date().toUTCString();
}
start() {
this.timerToken = setInterval(() => this.span.innerText = new Date().toUTCString(), 500);
}
stop() {
clearTimeout(this.timerToken);
}
}
window.onload = () => {
HTMLElement el = document.getElementById('content');
var greeter = new Greeter(el);
greeter.start();
};
I get an error
Compile Error. See error list for details .../app.ts (25,17): Expected ';'
Any clue why? I suspect I am missing something obvious.
let el: HTMLElement
orlet el: Node
– Zorgatone