UPDATE
TypeScript 1.5.3 added declarations for HTML Touch events to lib.d.ts
I can see that it supports UIEvent, but it does not seem to have interfaces for touch events.
This code indicates that “TouchEvent does not exist in the current scope.”
class Touchy {
private _element:Element;
constructor(theElement:Element) {
this._element = theElement;
theElement.addEventListener("touchstart", (theTouchEvent:TouchEvent) => alert("touchy"));
}
}
I can use UIEvent, but not TouchEvent. How would I handle TouchEvent’s with TypeScript? Thanks.
You have several options here:
First option: Extend UIEvent to have the members you’d expect on a TouchEvent (and only use them in touch event listeners):
Second option: Define your own TouchEvent interface and add a type assertion when binding the event