7
7
/// <reference lib="deno.webstorage" />
8
8
/// <reference lib="esnext" />
9
9
10
+ interface WindowEventMap {
11
+ "error" : ErrorEvent ;
12
+ }
13
+
10
14
declare class Window extends EventTarget {
11
15
new ( ) : Window ;
12
16
readonly window : Window & typeof globalThis ;
13
17
readonly self : Window & typeof globalThis ;
18
+ onerror : ( ( this : Window , ev : ErrorEvent ) => any ) | null ;
14
19
onload : ( ( this : Window , ev : Event ) => any ) | null ;
15
20
onunload : ( ( this : Window , ev : Event ) => any ) | null ;
16
21
close : ( ) => void ;
@@ -25,10 +30,38 @@ declare class Window extends EventTarget {
25
30
location : Location ;
26
31
localStorage : Storage ;
27
32
sessionStorage : Storage ;
33
+
34
+ addEventListener < K extends keyof WindowEventMap > (
35
+ type : K ,
36
+ listener : (
37
+ this : Window ,
38
+ ev : WindowEventMap [ K ] ,
39
+ ) => any ,
40
+ options ?: boolean | AddEventListenerOptions ,
41
+ ) : void ;
42
+ addEventListener (
43
+ type : string ,
44
+ listener : EventListenerOrEventListenerObject ,
45
+ options ?: boolean | AddEventListenerOptions ,
46
+ ) : void ;
47
+ removeEventListener < K extends keyof WindowEventMap > (
48
+ type : K ,
49
+ listener : (
50
+ this : Window ,
51
+ ev : WindowEventMap [ K ] ,
52
+ ) => any ,
53
+ options ?: boolean | EventListenerOptions ,
54
+ ) : void ;
55
+ removeEventListener (
56
+ type : string ,
57
+ listener : EventListenerOrEventListenerObject ,
58
+ options ?: boolean | EventListenerOptions ,
59
+ ) : void ;
28
60
}
29
61
30
62
declare var window : Window & typeof globalThis ;
31
63
declare var self : Window & typeof globalThis ;
64
+ declare var onerror : ( ( this : Window , ev : ErrorEvent ) => any ) | null ;
32
65
declare var onload : ( ( this : Window , ev : Event ) => any ) | null ;
33
66
declare var onunload : ( ( this : Window , ev : Event ) => any ) | null ;
34
67
declare var localStorage : Storage ;
@@ -77,10 +110,17 @@ declare function prompt(message?: string, defaultValue?: string): string | null;
77
110
* dispatchEvent(new Event('unload'));
78
111
* ```
79
112
*/
113
+ declare function addEventListener <
114
+ K extends keyof WindowEventMap ,
115
+ > (
116
+ type : K ,
117
+ listener : ( this : Window , ev : WindowEventMap [ K ] ) => any ,
118
+ options ?: boolean | AddEventListenerOptions ,
119
+ ) : void ;
80
120
declare function addEventListener (
81
121
type : string ,
82
- callback : EventListenerOrEventListenerObject | null ,
83
- options ?: boolean | AddEventListenerOptions | undefined ,
122
+ listener : EventListenerOrEventListenerObject ,
123
+ options ?: boolean | AddEventListenerOptions ,
84
124
) : void ;
85
125
86
126
/** Remove a previously registered event listener from the global scope
@@ -91,10 +131,17 @@ declare function addEventListener(
91
131
* removeEventListener('load', listener);
92
132
* ```
93
133
*/
134
+ declare function removeEventListener <
135
+ K extends keyof WindowEventMap ,
136
+ > (
137
+ type : K ,
138
+ listener : ( this : Window , ev : WindowEventMap [ K ] ) => any ,
139
+ options ?: boolean | EventListenerOptions ,
140
+ ) : void ;
94
141
declare function removeEventListener (
95
142
type : string ,
96
- callback : EventListenerOrEventListenerObject | null ,
97
- options ?: boolean | EventListenerOptions | undefined ,
143
+ listener : EventListenerOrEventListenerObject ,
144
+ options ?: boolean | EventListenerOptions ,
98
145
) : void ;
99
146
100
147
// TODO(nayeemrmn): Move this to `extensions/web` where its implementation is.
0 commit comments