Does TypeScript support TouchEvent?

后端 未结 3 1003
别跟我提以往
别跟我提以往 2021-01-08 00:31

UPDATE

TypeScript 1.5.3 added declarations for HTML Touch events to lib.d.ts

I can see that it supports UIEven

3条回答
  •  走了就别回头了
    2021-01-08 01:27

    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):

    interface UIEvent {
        targetTouches: { pageX: number; pageY: number; }[];
        // etc...
    }
    

    Second option: Define your own TouchEvent interface and add a type assertion when binding the event

    interface TouchEvent {
        (event: TouchEventArgs): void;
    }
    
    interface TouchEventArgs {
        targetTouches: { pageX: number; pageY: number; }[];
        // etc
    }
    
     theElement.addEventListener("touchstart", ((theTouchEvent:TouchEvent) => alert("touchy")));
    

提交回复
热议问题