UNPKG

3.54 kBTypeScriptView Raw
1/**
2 * The Event interface represents any event which takes place in the DOM; some are user-generated (such as mouse or keyboard events), while others are generated by APIs (such as
3 * events that indicate an animation has finished running, a video has been paused, and so forth). While events are usually triggered by such "external" sources, they can also be
4 * triggered programmatically, such as by calling the HTMLElement.click() method of an element, or by defining the event, then sending it to a specified target using
5 * EventTarget.dispatchEvent(). There are many types of events, some of which use other interfaces based on the main Event interface. Event itself contains the properties and
6 * methods which are common to all events.
7 */
8interface Event {
9 /**
10 * Returns true or false depending on how event was initialized. True if event goes through its target's ancestors in reverse tree order, and false otherwise.
11 */
12 readonly bubbles: boolean;
13 cancelBubble: boolean;
14 readonly cancelable: boolean;
15 /**
16 * Returns true or false depending on how event was initialized. True if event invokes listeners past a ShadowRoot node that is the root of its target, and false otherwise.
17 */
18 readonly composed: boolean;
19 readonly defaultPrevented: boolean;
20 readonly eventPhase: number;
21 /**
22 * Returns true if event was dispatched by the user agent, and
23 * false otherwise.
24 */
25 readonly isTrusted: boolean;
26 returnValue: boolean;
27 /**
28 * Returns the event's timestamp as the number of milliseconds measured relative to
29 * the time origin.
30 */
31 readonly timeStamp: number;
32 /**
33 * Unauthorized and redirect error status codes (for example 401, 403, 301, 307)
34 */
35 readonly status?: number | undefined;
36 /**
37 * Returns the type of event, e.g.
38 * "click", "hashchange", or
39 * "submit".
40 */
41 readonly type: string;
42 readonly AT_TARGET: 2;
43 readonly BUBBLING_PHASE: 3;
44 readonly CAPTURING_PHASE: 1;
45 readonly NONE: 0;
46 composedPath(): any[];
47 initEvent(type: string, bubbles?: boolean, cancelable?: boolean): void;
48 preventDefault(): void;
49 /**
50 * Invoking this method prevents event from reaching
51 * any registered event listeners after the current one finishes running and, when dispatched in a tree, also prevents event from reaching any
52 * other objects.
53 */
54 stopImmediatePropagation(): void;
55 /**
56 * When dispatched in a tree, invoking this method prevents event from reaching any objects other than the current object.
57 */
58 stopPropagation(): void;
59}
60
61interface EventInit {
62 bubbles?: boolean | undefined;
63 cancelable?: boolean | undefined;
64 composed?: boolean | undefined;
65}
66
67interface MessageEventInit<T = any> extends EventInit {
68 data?: T | undefined;
69 lastEventId?: string | undefined;
70 origin?: string | undefined;
71}
72
73/** The MessageEvent interface represents a message received by a target object. */
74interface MessageEvent<T = any> extends Event {
75 /**
76 * Returns the data of the message.
77 */
78 readonly data: T;
79 /**
80 * Returns the last event ID string, for server-sent events.
81 */
82 readonly lastEventId: string;
83 /**
84 * Returns the origin of the message, for server-sent events and
85 * cross-document messaging.
86 */
87 readonly origin: string;
88}
89declare var MessageEvent: {
90 prototype: MessageEvent;
91 new<T>(type: string, eventInitDict?: MessageEventInit<T>): MessageEvent<T>;
92};