What Typescript type is Angular2 event

后端 未结 3 951
广开言路
广开言路 2020-12-07 12:22

If I have the following button in an html file

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-07 12:52

    Some commonly used events and their related names (MouseEvent, FocusEvent, TouchEvent, DragEvent, KeyboardEvent):

    | MouseEvent | FocusEvent |  TouchEvent | DragEvent | KeyboardEvent |
    |:----------:|:----------:|:-----------:|:---------:|:-------------:|
    |    click   |    focus   |  touchstart |    drag   |    keypress   |
    |   mouseup  |    blur    |  touchmove  |    drop   |     keyup     |
    | mouseleave |   focusin  | touchcancel |  dragend  |    keydown    |
    |  mouseover |  focusout  |   touchend  |  dragover |               |
    

    The generic Event is associated to:

    • close
    • change
    • invalid
    • play
    • reset
    • scroll
    • select
    • submit
    • toggle
    • waiting

    If you dig in Typescript's repository, dom.generated.d.ts provides a global events interface (credit goes to Eric's answer) where you may find all the event handlers mappings at line 5725:

    interface GlobalEventHandlersEventMap {
      "abort": UIEvent;
      "animationcancel": AnimationEvent;
      "animationend": AnimationEvent;
      "animationiteration": AnimationEvent;
      "animationstart": AnimationEvent;
      "auxclick": MouseEvent;
      "blur": FocusEvent;
      "cancel": Event;
      "canplay": Event;
      "canplaythrough": Event;
      "change": Event;
      "click": MouseEvent;
      "close": Event;
      "contextmenu": MouseEvent;
      "cuechange": Event;
      "dblclick": MouseEvent;
      "drag": DragEvent;
      "dragend": DragEvent;
      "dragenter": DragEvent;
      "dragexit": Event;
      "dragleave": DragEvent;
      "dragover": DragEvent;
      "dragstart": DragEvent;
      "drop": DragEvent;
      "durationchange": Event;
      "emptied": Event;
      "ended": Event;
      "error": ErrorEvent;
      "focus": FocusEvent;
      "focusin": FocusEvent;
      "focusout": FocusEvent;
      "gotpointercapture": PointerEvent;
      "input": Event;
      "invalid": Event;
      "keydown": KeyboardEvent;
      "keypress": KeyboardEvent;
      "keyup": KeyboardEvent;
      "load": Event;
      "loadeddata": Event;
      "loadedmetadata": Event;
      "loadend": ProgressEvent;
      "loadstart": Event;
      "lostpointercapture": PointerEvent;
      "mousedown": MouseEvent;
      "mouseenter": MouseEvent;
      "mouseleave": MouseEvent;
      "mousemove": MouseEvent;
      "mouseout": MouseEvent;
      "mouseover": MouseEvent;
      "mouseup": MouseEvent;
      "pause": Event;
      "play": Event;
      "playing": Event;
      "pointercancel": PointerEvent;
      "pointerdown": PointerEvent;
      "pointerenter": PointerEvent;
      "pointerleave": PointerEvent;
      "pointermove": PointerEvent;
      "pointerout": PointerEvent;
      "pointerover": PointerEvent;
      "pointerup": PointerEvent;
      "progress": ProgressEvent;
      "ratechange": Event;
      "reset": Event;
      "resize": UIEvent;
      "scroll": Event;
      "securitypolicyviolation": SecurityPolicyViolationEvent;
      "seeked": Event;
      "seeking": Event;
      "select": Event;
      "selectionchange": Event;
      "selectstart": Event;
      "stalled": Event;
      "submit": Event;
      "suspend": Event;
      "timeupdate": Event;
      "toggle": Event;
      "touchcancel": TouchEvent;
      "touchend": TouchEvent;
      "touchmove": TouchEvent;
      "touchstart": TouchEvent;
      "transitioncancel": TransitionEvent;
      "transitionend": TransitionEvent;
      "transitionrun": TransitionEvent;
      "transitionstart": TransitionEvent;
      "volumechange": Event;
      "waiting": Event;
      "wheel": WheelEvent;
    }
    

提交回复
热议问题