From acd8fc21eef3f2e7f35b1f788fe5c2f0db10fede Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Scarcella?= Date: Thu, 28 Sep 2023 23:39:07 -0300 Subject: [PATCH 1/7] Hopefully fixes #299 --- baselines/audioworklet.generated.d.ts | 20 ++--- baselines/dom.generated.d.ts | 40 ++++----- baselines/serviceworker.generated.d.ts | 20 ++--- baselines/sharedworker.generated.d.ts | 20 ++--- baselines/webworker.generated.d.ts | 20 ++--- inputfiles/addedTypes.jsonc | 36 +++++++- inputfiles/overridingTypes.jsonc | 116 ++++++++++++++++++++++++- 7 files changed, 207 insertions(+), 65 deletions(-) diff --git a/baselines/audioworklet.generated.d.ts b/baselines/audioworklet.generated.d.ts index c4d8f4336..78a660b66 100644 --- a/baselines/audioworklet.generated.d.ts +++ b/baselines/audioworklet.generated.d.ts @@ -433,7 +433,7 @@ declare var ErrorEvent: { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event) */ -interface Event { +interface Event { /** * 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. * @@ -463,7 +463,7 @@ interface Event { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/currentTarget) */ - readonly currentTarget: EventTarget | null; + readonly currentTarget: T | null; /** * Returns true if preventDefault() was invoked successfully to indicate cancelation, and false otherwise. * @@ -499,7 +499,7 @@ interface Event { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/target) */ - readonly target: EventTarget | null; + readonly target: T | null; /** * Returns the event's timestamp as the number of milliseconds measured relative to the time origin. * @@ -557,12 +557,12 @@ declare var Event: { readonly BUBBLING_PHASE: 3; }; -interface EventListener { - (evt: Event): void; +interface EventListener { + (evt: Event): void; } -interface EventListenerObject { - handleEvent(object: Event): void; +interface EventListenerObject { + handleEvent(object: Event): void; } /** @@ -588,7 +588,7 @@ interface EventTarget { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventTarget/addEventListener) */ - addEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: AddEventListenerOptions | boolean): void; + addEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: AddEventListenerOptions | boolean): void; /** * Dispatches a synthetic event event to target and returns true if either event's cancelable attribute value is false or its preventDefault() method was not invoked, and false otherwise. * @@ -600,7 +600,7 @@ interface EventTarget { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventTarget/removeEventListener) */ - removeEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: EventListenerOptions | boolean): void; + removeEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: EventListenerOptions | boolean): void; } declare var EventTarget: { @@ -1402,7 +1402,7 @@ declare function registerProcessor(name: string, processorCtor: AudioWorkletProc type AllowSharedBufferSource = ArrayBuffer | ArrayBufferView; type BufferSource = ArrayBufferView | ArrayBuffer; type DOMHighResTimeStamp = number; -type EventListenerOrEventListenerObject = EventListener | EventListenerObject; +type EventListenerOrEventListenerObject = EventListener | EventListenerObject; type MessageEventSource = MessagePort; type ReadableStreamController = ReadableStreamDefaultController | ReadableByteStreamController; type ReadableStreamReadResult = ReadableStreamReadValueResult | ReadableStreamReadDoneResult; diff --git a/baselines/dom.generated.d.ts b/baselines/dom.generated.d.ts index 919e6a6a4..74708a20b 100644 --- a/baselines/dom.generated.d.ts +++ b/baselines/dom.generated.d.ts @@ -5721,7 +5721,7 @@ declare var Comment: { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/CompositionEvent) */ -interface CompositionEvent extends UIEvent { +interface CompositionEvent extends UIEvent { /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/CompositionEvent/data) */ readonly data: string; /** @@ -7462,7 +7462,7 @@ declare var DocumentType: { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/DragEvent) */ -interface DragEvent extends MouseEvent { +interface DragEvent extends MouseEvent { /** * Returns the DataTransfer object for the event. * @@ -7982,7 +7982,7 @@ declare var ErrorEvent: { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event) */ -interface Event { +interface Event { /** * 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. * @@ -8012,7 +8012,7 @@ interface Event { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/currentTarget) */ - readonly currentTarget: EventTarget | null; + readonly currentTarget: T | null; /** * Returns true if preventDefault() was invoked successfully to indicate cancelation, and false otherwise. * @@ -8048,7 +8048,7 @@ interface Event { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/target) */ - readonly target: EventTarget | null; + readonly target: T | null; /** * Returns the event's timestamp as the number of milliseconds measured relative to the time origin. * @@ -8116,12 +8116,12 @@ declare var EventCounts: { new(): EventCounts; }; -interface EventListener { - (evt: Event): void; +interface EventListener { + (evt: Event): void; } -interface EventListenerObject { - handleEvent(object: Event): void; +interface EventListenerObject { + handleEvent(object: Event): void; } interface EventSourceEventMap { @@ -8204,7 +8204,7 @@ interface EventTarget { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventTarget/addEventListener) */ - addEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: AddEventListenerOptions | boolean): void; + addEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: AddEventListenerOptions | boolean): void; /** * Dispatches a synthetic event event to target and returns true if either event's cancelable attribute value is false or its preventDefault() method was not invoked, and false otherwise. * @@ -8216,7 +8216,7 @@ interface EventTarget { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventTarget/removeEventListener) */ - removeEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: EventListenerOptions | boolean): void; + removeEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: EventListenerOptions | boolean): void; } declare var EventTarget: { @@ -8501,7 +8501,7 @@ declare var FileSystemWritableFileStream: { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/FocusEvent) */ -interface FocusEvent extends UIEvent { +interface FocusEvent extends UIEvent { /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/FocusEvent/relatedTarget) */ readonly relatedTarget: EventTarget | null; } @@ -14303,7 +14303,7 @@ declare var InputDeviceInfo: { }; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/InputEvent) */ -interface InputEvent extends UIEvent { +interface InputEvent extends UIEvent { /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/InputEvent/data) */ readonly data: string | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/InputEvent/dataTransfer) */ @@ -14385,7 +14385,7 @@ interface KHR_parallel_shader_compile { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/KeyboardEvent) */ -interface KeyboardEvent extends UIEvent { +interface KeyboardEvent extends UIEvent { /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/KeyboardEvent/altKey) */ readonly altKey: boolean; /** @@ -15592,7 +15592,7 @@ declare var MimeTypeArray: { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/MouseEvent) */ -interface MouseEvent extends UIEvent { +interface MouseEvent extends UIEvent { /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/MouseEvent/altKey) */ readonly altKey: boolean; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/MouseEvent/button) */ @@ -17593,7 +17593,7 @@ declare var PluginArray: { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/PointerEvent) */ -interface PointerEvent extends MouseEvent { +interface PointerEvent extends MouseEvent { /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/PointerEvent/height) */ readonly height: number; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/PointerEvent/isPrimary) */ @@ -22414,7 +22414,7 @@ declare var Touch: { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TouchEvent) */ -interface TouchEvent extends UIEvent { +interface TouchEvent extends UIEvent { /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/TouchEvent/altKey) */ readonly altKey: boolean; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/TouchEvent/changedTouches) */ @@ -22562,7 +22562,7 @@ declare var TreeWalker: { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/UIEvent) */ -interface UIEvent extends Event { +interface UIEvent extends Event { /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/UIEvent/detail) */ readonly detail: number; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/UIEvent/view) */ @@ -25596,7 +25596,7 @@ declare var WebTransportError: { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WheelEvent) */ -interface WheelEvent extends MouseEvent { +interface WheelEvent extends MouseEvent { /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/WheelEvent/deltaMode) */ readonly deltaMode: number; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/WheelEvent/deltaX) */ @@ -28041,7 +28041,7 @@ type ConstrainDouble = number | ConstrainDoubleRange; type ConstrainULong = number | ConstrainULongRange; type DOMHighResTimeStamp = number; type EpochTimeStamp = number; -type EventListenerOrEventListenerObject = EventListener | EventListenerObject; +type EventListenerOrEventListenerObject = EventListener | EventListenerObject; type FileSystemWriteChunkType = BufferSource | Blob | string | WriteParams; type Float32List = Float32Array | GLfloat[]; type FormDataEntryValue = File | string; diff --git a/baselines/serviceworker.generated.d.ts b/baselines/serviceworker.generated.d.ts index 8446995c0..a211807a5 100644 --- a/baselines/serviceworker.generated.d.ts +++ b/baselines/serviceworker.generated.d.ts @@ -2202,7 +2202,7 @@ declare var ErrorEvent: { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event) */ -interface Event { +interface Event { /** * 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. * @@ -2232,7 +2232,7 @@ interface Event { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/currentTarget) */ - readonly currentTarget: EventTarget | null; + readonly currentTarget: T | null; /** * Returns true if preventDefault() was invoked successfully to indicate cancelation, and false otherwise. * @@ -2268,7 +2268,7 @@ interface Event { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/target) */ - readonly target: EventTarget | null; + readonly target: T | null; /** * Returns the event's timestamp as the number of milliseconds measured relative to the time origin. * @@ -2326,12 +2326,12 @@ declare var Event: { readonly BUBBLING_PHASE: 3; }; -interface EventListener { - (evt: Event): void; +interface EventListener { + (evt: Event): void; } -interface EventListenerObject { - handleEvent(object: Event): void; +interface EventListenerObject { + handleEvent(object: Event): void; } interface EventSourceEventMap { @@ -2414,7 +2414,7 @@ interface EventTarget { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventTarget/addEventListener) */ - addEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: AddEventListenerOptions | boolean): void; + addEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: AddEventListenerOptions | boolean): void; /** * Dispatches a synthetic event event to target and returns true if either event's cancelable attribute value is false or its preventDefault() method was not invoked, and false otherwise. * @@ -2426,7 +2426,7 @@ interface EventTarget { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventTarget/removeEventListener) */ - removeEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: EventListenerOptions | boolean): void; + removeEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: EventListenerOptions | boolean): void; } declare var EventTarget: { @@ -8547,7 +8547,7 @@ type CSSUnparsedSegment = string | CSSVariableReferenceValue; type CanvasImageSource = ImageBitmap | OffscreenCanvas; type DOMHighResTimeStamp = number; type EpochTimeStamp = number; -type EventListenerOrEventListenerObject = EventListener | EventListenerObject; +type EventListenerOrEventListenerObject = EventListener | EventListenerObject; type FileSystemWriteChunkType = BufferSource | Blob | string | WriteParams; type Float32List = Float32Array | GLfloat[]; type FormDataEntryValue = File | string; diff --git a/baselines/sharedworker.generated.d.ts b/baselines/sharedworker.generated.d.ts index 145a3c819..883e150ed 100644 --- a/baselines/sharedworker.generated.d.ts +++ b/baselines/sharedworker.generated.d.ts @@ -2129,7 +2129,7 @@ declare var ErrorEvent: { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event) */ -interface Event { +interface Event { /** * 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. * @@ -2159,7 +2159,7 @@ interface Event { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/currentTarget) */ - readonly currentTarget: EventTarget | null; + readonly currentTarget: T | null; /** * Returns true if preventDefault() was invoked successfully to indicate cancelation, and false otherwise. * @@ -2195,7 +2195,7 @@ interface Event { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/target) */ - readonly target: EventTarget | null; + readonly target: T | null; /** * Returns the event's timestamp as the number of milliseconds measured relative to the time origin. * @@ -2253,12 +2253,12 @@ declare var Event: { readonly BUBBLING_PHASE: 3; }; -interface EventListener { - (evt: Event): void; +interface EventListener { + (evt: Event): void; } -interface EventListenerObject { - handleEvent(object: Event): void; +interface EventListenerObject { + handleEvent(object: Event): void; } interface EventSourceEventMap { @@ -2341,7 +2341,7 @@ interface EventTarget { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventTarget/addEventListener) */ - addEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: AddEventListenerOptions | boolean): void; + addEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: AddEventListenerOptions | boolean): void; /** * Dispatches a synthetic event event to target and returns true if either event's cancelable attribute value is false or its preventDefault() method was not invoked, and false otherwise. * @@ -2353,7 +2353,7 @@ interface EventTarget { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventTarget/removeEventListener) */ - removeEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: EventListenerOptions | boolean): void; + removeEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: EventListenerOptions | boolean): void; } declare var EventTarget: { @@ -8556,7 +8556,7 @@ type CSSUnparsedSegment = string | CSSVariableReferenceValue; type CanvasImageSource = ImageBitmap | OffscreenCanvas; type DOMHighResTimeStamp = number; type EpochTimeStamp = number; -type EventListenerOrEventListenerObject = EventListener | EventListenerObject; +type EventListenerOrEventListenerObject = EventListener | EventListenerObject; type FileSystemWriteChunkType = BufferSource | Blob | string | WriteParams; type Float32List = Float32Array | GLfloat[]; type FormDataEntryValue = File | string; diff --git a/baselines/webworker.generated.d.ts b/baselines/webworker.generated.d.ts index 61201af93..e9399ec01 100644 --- a/baselines/webworker.generated.d.ts +++ b/baselines/webworker.generated.d.ts @@ -2405,7 +2405,7 @@ declare var ErrorEvent: { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event) */ -interface Event { +interface Event { /** * 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. * @@ -2435,7 +2435,7 @@ interface Event { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/currentTarget) */ - readonly currentTarget: EventTarget | null; + readonly currentTarget: T | null; /** * Returns true if preventDefault() was invoked successfully to indicate cancelation, and false otherwise. * @@ -2471,7 +2471,7 @@ interface Event { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/target) */ - readonly target: EventTarget | null; + readonly target: T | null; /** * Returns the event's timestamp as the number of milliseconds measured relative to the time origin. * @@ -2529,12 +2529,12 @@ declare var Event: { readonly BUBBLING_PHASE: 3; }; -interface EventListener { - (evt: Event): void; +interface EventListener { + (evt: Event): void; } -interface EventListenerObject { - handleEvent(object: Event): void; +interface EventListenerObject { + handleEvent(object: Event): void; } interface EventSourceEventMap { @@ -2617,7 +2617,7 @@ interface EventTarget { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventTarget/addEventListener) */ - addEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: AddEventListenerOptions | boolean): void; + addEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: AddEventListenerOptions | boolean): void; /** * Dispatches a synthetic event event to target and returns true if either event's cancelable attribute value is false or its preventDefault() method was not invoked, and false otherwise. * @@ -2629,7 +2629,7 @@ interface EventTarget { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventTarget/removeEventListener) */ - removeEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: EventListenerOptions | boolean): void; + removeEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: EventListenerOptions | boolean): void; } declare var EventTarget: { @@ -9272,7 +9272,7 @@ type CSSUnparsedSegment = string | CSSVariableReferenceValue; type CanvasImageSource = ImageBitmap | OffscreenCanvas | VideoFrame; type DOMHighResTimeStamp = number; type EpochTimeStamp = number; -type EventListenerOrEventListenerObject = EventListener | EventListenerObject; +type EventListenerOrEventListenerObject = EventListener | EventListenerObject; type FileSystemWriteChunkType = BufferSource | Blob | string | WriteParams; type Float32List = Float32Array | GLfloat[]; type FormDataEntryValue = File | string; diff --git a/inputfiles/addedTypes.jsonc b/inputfiles/addedTypes.jsonc index dce7677b9..6b38ff206 100644 --- a/inputfiles/addedTypes.jsonc +++ b/inputfiles/addedTypes.jsonc @@ -772,6 +772,13 @@ "EventListener": { "name": "EventListener", "noInterfaceObject": true, + "typeParameters": [ + { + "name": "T", + "default": "EventTarget", + "extends": "EventTarget" + } + ], "methods": { "method": { // This is a hack to add a call signature, but I think it's reasonable @@ -779,7 +786,7 @@ // emitter for this one case. "callable": { "overrideSignatures": [ - "(evt: Event): void" + "(evt: Event): void" ] } } @@ -788,11 +795,18 @@ "EventListenerObject": { "name": "EventListenerObject", "noInterfaceObject": true, + "typeParameters": [ + { + "name": "T", + "default": "EventTarget", + "extends": "EventTarget" + } + ], "methods": { "method": { "handleEvent": { "overrideSignatures": [ - "handleEvent(object: Event): void" + "handleEvent(object: Event): void" ] } } @@ -916,6 +930,15 @@ } }, "UIEvent": { + "extends": "Event", + "typeParameters": [ + { + "name": "T", + "default": "EventTarget", + "extends": "EventTarget" + } + ], + //!!!!!!!!!!!!! "properties": { "property": { "which": { @@ -1513,7 +1536,14 @@ }, { "name": "EventListenerOrEventListenerObject", - "overrideType": "EventListener | EventListenerObject" + "overrideType": "EventListener | EventListenerObject", + "typeParameters": [ + { + "name": "T", + "default": "EventTarget", + "extends": "EventTarget" + } + ] }, { "name": "OptionalPrefixToken", diff --git a/inputfiles/overridingTypes.jsonc b/inputfiles/overridingTypes.jsonc index 38b4d59f9..a5d21a1c6 100644 --- a/inputfiles/overridingTypes.jsonc +++ b/inputfiles/overridingTypes.jsonc @@ -1729,7 +1729,79 @@ } } }, + "Event": { + // !!!!!!!!! + "typeParameters": [ + { + "name": "T", + "default": "EventTarget", + "extends": "EventTarget" + } + ], + "properties": { + "property": { + "target": { + "name": "target", + "readonly": true, + "overrideType": "T" + }, + "currentTarget": { + "name": "currentTarget", + "readonly": true, + "overrideType": "T" + } + } + } + }, + "CompositionEvent": { + "typeParameters": [ + { + "name": "T", + "default": "EventTarget", + "extends": "EventTarget" + } + ], + "extends": "UIEvent" + }, + "FocusEvent": { + "typeParameters": [ + { + "name": "T", + "default": "EventTarget", + "extends": "EventTarget" + } + ], + "extends": "UIEvent" + }, + "InputEvent": { + "typeParameters": [ + { + "name": "T", + "default": "EventTarget", + "extends": "EventTarget" + } + ], + "extends": "UIEvent" + }, + "KeyboardEvent": { + "typeParameters": [ + { + "name": "T", + "default": "EventTarget", + "extends": "EventTarget" + } + ], + "extends": "UIEvent" + }, "MouseEvent": { + "typeParameters": [ + { + "name": "T", + "default": "EventTarget", + "extends": "EventTarget" + } + ], + "extends": "UIEvent" , "methods": { "method": { "initMouseEvent": { @@ -1741,6 +1813,46 @@ } } }, + "TouchEvent": { + "typeParameters": [ + { + "name": "T", + "default": "EventTarget", + "extends": "EventTarget" + } + ], + "extends": "UIEvent" + }, + "DragEvent": { + "typeParameters": [ + { + "name": "T", + "default": "EventTarget", + "extends": "EventTarget" + } + ], + "extends": "MouseEvent" + }, + "PointerEvent": { + "typeParameters": [ + { + "name": "T", + "default": "EventTarget", + "extends": "EventTarget" + } + ], + "extends": "MouseEvent" + }, + "WheelEvent": { + "typeParameters": [ + { + "name": "T", + "default": "EventTarget", + "extends": "EventTarget" + } + ], + "extends": "MouseEvent" + }, "DOMException": { "extends": "Error" }, @@ -2989,7 +3101,7 @@ "param": [ { "name": "callback", - "overrideType": "EventListenerOrEventListenerObject" + "overrideType": "EventListenerOrEventListenerObject" } ] } @@ -3001,7 +3113,7 @@ "param": [ { "name": "callback", - "overrideType": "EventListenerOrEventListenerObject" + "overrideType": "EventListenerOrEventListenerObject" } ] } From 8f85aaaa4432e0af6ef86af2ca341fe138d766e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Scarcella?= Date: Fri, 29 Sep 2023 12:26:39 -0300 Subject: [PATCH 2/7] Cleanup --- inputfiles/addedTypes.jsonc | 1 - inputfiles/overridingTypes.jsonc | 1 - 2 files changed, 2 deletions(-) diff --git a/inputfiles/addedTypes.jsonc b/inputfiles/addedTypes.jsonc index 6b38ff206..4ee9537be 100644 --- a/inputfiles/addedTypes.jsonc +++ b/inputfiles/addedTypes.jsonc @@ -938,7 +938,6 @@ "extends": "EventTarget" } ], - //!!!!!!!!!!!!! "properties": { "property": { "which": { diff --git a/inputfiles/overridingTypes.jsonc b/inputfiles/overridingTypes.jsonc index a5d21a1c6..332620a93 100644 --- a/inputfiles/overridingTypes.jsonc +++ b/inputfiles/overridingTypes.jsonc @@ -1730,7 +1730,6 @@ } }, "Event": { - // !!!!!!!!! "typeParameters": [ { "name": "T", From cabf7f78950c0c6a4f67493c169e5bd1f0f22a88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Scarcella?= Date: Fri, 2 Feb 2024 13:08:06 -0300 Subject: [PATCH 3/7] reverting type of target to EventTarget --- baselines/audioworklet.generated.d.ts | 2 +- baselines/dom.generated.d.ts | 2 +- baselines/serviceworker.generated.d.ts | 2 +- baselines/sharedworker.generated.d.ts | 2 +- baselines/webworker.generated.d.ts | 2 +- inputfiles/overridingTypes.jsonc | 5 ----- 6 files changed, 5 insertions(+), 10 deletions(-) diff --git a/baselines/audioworklet.generated.d.ts b/baselines/audioworklet.generated.d.ts index 78a660b66..061d8692e 100644 --- a/baselines/audioworklet.generated.d.ts +++ b/baselines/audioworklet.generated.d.ts @@ -499,7 +499,7 @@ interface Event { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/target) */ - readonly target: T | null; + readonly target: EventTarget | null; /** * Returns the event's timestamp as the number of milliseconds measured relative to the time origin. * diff --git a/baselines/dom.generated.d.ts b/baselines/dom.generated.d.ts index 74708a20b..5c2676af0 100644 --- a/baselines/dom.generated.d.ts +++ b/baselines/dom.generated.d.ts @@ -8048,7 +8048,7 @@ interface Event { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/target) */ - readonly target: T | null; + readonly target: EventTarget | null; /** * Returns the event's timestamp as the number of milliseconds measured relative to the time origin. * diff --git a/baselines/serviceworker.generated.d.ts b/baselines/serviceworker.generated.d.ts index a211807a5..aaf543c2f 100644 --- a/baselines/serviceworker.generated.d.ts +++ b/baselines/serviceworker.generated.d.ts @@ -2268,7 +2268,7 @@ interface Event { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/target) */ - readonly target: T | null; + readonly target: EventTarget | null; /** * Returns the event's timestamp as the number of milliseconds measured relative to the time origin. * diff --git a/baselines/sharedworker.generated.d.ts b/baselines/sharedworker.generated.d.ts index 883e150ed..00eb9f6e5 100644 --- a/baselines/sharedworker.generated.d.ts +++ b/baselines/sharedworker.generated.d.ts @@ -2195,7 +2195,7 @@ interface Event { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/target) */ - readonly target: T | null; + readonly target: EventTarget | null; /** * Returns the event's timestamp as the number of milliseconds measured relative to the time origin. * diff --git a/baselines/webworker.generated.d.ts b/baselines/webworker.generated.d.ts index e9399ec01..88977a8e2 100644 --- a/baselines/webworker.generated.d.ts +++ b/baselines/webworker.generated.d.ts @@ -2471,7 +2471,7 @@ interface Event { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/target) */ - readonly target: T | null; + readonly target: EventTarget | null; /** * Returns the event's timestamp as the number of milliseconds measured relative to the time origin. * diff --git a/inputfiles/overridingTypes.jsonc b/inputfiles/overridingTypes.jsonc index 332620a93..9d0682139 100644 --- a/inputfiles/overridingTypes.jsonc +++ b/inputfiles/overridingTypes.jsonc @@ -1739,11 +1739,6 @@ ], "properties": { "property": { - "target": { - "name": "target", - "readonly": true, - "overrideType": "T" - }, "currentTarget": { "name": "currentTarget", "readonly": true, From d618a12b733b6703695075f993f2f7e8adec095d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Scarcella?= Date: Fri, 2 Feb 2024 13:24:57 -0300 Subject: [PATCH 4/7] Moved Event definitions to addedTypes --- inputfiles/addedTypes.jsonc | 18 ++++++++++++++++++ inputfiles/overridingTypes.jsonc | 18 ------------------ 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/inputfiles/addedTypes.jsonc b/inputfiles/addedTypes.jsonc index 4ee9537be..b814ba449 100644 --- a/inputfiles/addedTypes.jsonc +++ b/inputfiles/addedTypes.jsonc @@ -764,6 +764,24 @@ "extends": "DOMRect", "noInterfaceObject": true }, + "Event": { + "typeParameters": [ + { + "name": "T", + "default": "EventTarget", + "extends": "EventTarget" + } + ], + "properties": { + "property": { + "currentTarget": { + "name": "currentTarget", + "readonly": true, + "overrideType": "T" + } + } + } + }, /* Keeping EventListener and EventListenerObject isn't the most elegant way to handle the event listeners, but we need to keep the EventListener as an extendable interface diff --git a/inputfiles/overridingTypes.jsonc b/inputfiles/overridingTypes.jsonc index 9d0682139..c6b3805cd 100644 --- a/inputfiles/overridingTypes.jsonc +++ b/inputfiles/overridingTypes.jsonc @@ -1729,24 +1729,6 @@ } } }, - "Event": { - "typeParameters": [ - { - "name": "T", - "default": "EventTarget", - "extends": "EventTarget" - } - ], - "properties": { - "property": { - "currentTarget": { - "name": "currentTarget", - "readonly": true, - "overrideType": "T" - } - } - } - }, "CompositionEvent": { "typeParameters": [ { From 96fd9613a8c586a8fdc076a9cb12674a8b1c3998 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Scarcella?= Date: Thu, 22 Feb 2024 17:19:15 -0300 Subject: [PATCH 5/7] Generating extension of generic event types by code instead of overriding JSON --- inputfiles/overridingTypes.jsonc | 88 -------------------------------- src/build/emitter.ts | 26 ++++++++-- src/build/helpers.ts | 2 + 3 files changed, 23 insertions(+), 93 deletions(-) diff --git a/inputfiles/overridingTypes.jsonc b/inputfiles/overridingTypes.jsonc index c6b3805cd..abfbb66e1 100644 --- a/inputfiles/overridingTypes.jsonc +++ b/inputfiles/overridingTypes.jsonc @@ -1729,55 +1729,7 @@ } } }, - "CompositionEvent": { - "typeParameters": [ - { - "name": "T", - "default": "EventTarget", - "extends": "EventTarget" - } - ], - "extends": "UIEvent" - }, - "FocusEvent": { - "typeParameters": [ - { - "name": "T", - "default": "EventTarget", - "extends": "EventTarget" - } - ], - "extends": "UIEvent" - }, - "InputEvent": { - "typeParameters": [ - { - "name": "T", - "default": "EventTarget", - "extends": "EventTarget" - } - ], - "extends": "UIEvent" - }, - "KeyboardEvent": { - "typeParameters": [ - { - "name": "T", - "default": "EventTarget", - "extends": "EventTarget" - } - ], - "extends": "UIEvent" - }, "MouseEvent": { - "typeParameters": [ - { - "name": "T", - "default": "EventTarget", - "extends": "EventTarget" - } - ], - "extends": "UIEvent" , "methods": { "method": { "initMouseEvent": { @@ -1789,46 +1741,6 @@ } } }, - "TouchEvent": { - "typeParameters": [ - { - "name": "T", - "default": "EventTarget", - "extends": "EventTarget" - } - ], - "extends": "UIEvent" - }, - "DragEvent": { - "typeParameters": [ - { - "name": "T", - "default": "EventTarget", - "extends": "EventTarget" - } - ], - "extends": "MouseEvent" - }, - "PointerEvent": { - "typeParameters": [ - { - "name": "T", - "default": "EventTarget", - "extends": "EventTarget" - } - ], - "extends": "MouseEvent" - }, - "WheelEvent": { - "typeParameters": [ - { - "name": "T", - "default": "EventTarget", - "extends": "EventTarget" - } - ], - "extends": "MouseEvent" - }, "DOMException": { "extends": "Error" }, diff --git a/src/build/emitter.ts b/src/build/emitter.ts index 141b35843..06bafba56 100644 --- a/src/build/emitter.ts +++ b/src/build/emitter.ts @@ -9,6 +9,7 @@ import { integerTypes, baseTypeConversionMap, assertUnique, + genericEventSupertypes, } from "./helpers.js"; import { collectLegacyNamespaceTypes } from "./legacy-namespace.js"; @@ -1202,17 +1203,32 @@ export function emitWebIdl( emitComments(i, printer.printLine); - printer.print( - `interface ${getNameWithTypeParameter(i.typeParameters, processedIName)}` - ); - const finalExtends = [i.extends || "Object"] .concat(getImplementList(i.name)) .filter((i) => i !== "Object") .map(processIName); + const extendedGenericEventSupertype = i.typeParameters + ? undefined + : finalExtends.find((name) => genericEventSupertypes.has(name)); + + printer.print( + `interface ${getNameWithTypeParameter( + extendedGenericEventSupertype + ? [{ name: "T", default: "EventTarget", extends: "EventTarget" }] + : i.typeParameters, + processedIName + )}` + ); + if (finalExtends.length) { - printer.print(` extends ${assertUnique(finalExtends).join(", ")}`); + printer.print( + ` extends ${assertUnique( + finalExtends.map((name) => + name === extendedGenericEventSupertype ? `${name}` : name + ) + ).join(", ")}` + ); } printer.print(" {"); printer.endLine(); diff --git a/src/build/helpers.ts b/src/build/helpers.ts index 329dc2959..bd17be32a 100644 --- a/src/build/helpers.ts +++ b/src/build/helpers.ts @@ -62,6 +62,8 @@ export const baseTypeConversionMap = new Map([ ["EventHandler", "EventHandler"], ]); +export const genericEventSupertypes = new Set(["UIEvent", "MouseEvent"]); + export function deepFilter( obj: T, fn: (o: any, n: string | undefined) => boolean From 83982b7001805c66f906ed8146b7996b28e61d58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Scarcella?= Date: Thu, 22 Feb 2024 17:37:53 -0300 Subject: [PATCH 6/7] Fixing linter --- src/build/emitter.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/build/emitter.ts b/src/build/emitter.ts index ff59e865d..127ce4d5c 100644 --- a/src/build/emitter.ts +++ b/src/build/emitter.ts @@ -1217,17 +1217,17 @@ export function emitWebIdl( extendedGenericEventSupertype ? [{ name: "T", default: "EventTarget", extends: "EventTarget" }] : i.typeParameters, - processedIName - )}` + processedIName, + )}`, ); if (finalExtends.length) { printer.print( ` extends ${assertUnique( finalExtends.map((name) => - name === extendedGenericEventSupertype ? `${name}` : name - ) - ).join(", ")}` + name === extendedGenericEventSupertype ? `${name}` : name, + ), + ).join(", ")}`, ); } printer.print(" {"); From 2a2157ea41cb06360f1606d66b93e583d6650256 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Scarcella?= Date: Fri, 23 Feb 2024 18:02:32 -0300 Subject: [PATCH 7/7] (draft) adding handing of onevent --- baselines/dom.generated.d.ts | 206 +++++++++++++++++------------------ inputfiles/addedTypes.jsonc | 7 ++ src/build/emitter.ts | 28 ++++- 3 files changed, 135 insertions(+), 106 deletions(-) diff --git a/baselines/dom.generated.d.ts b/baselines/dom.generated.d.ts index dcfb4669f..ae04ac6ae 100644 --- a/baselines/dom.generated.d.ts +++ b/baselines/dom.generated.d.ts @@ -6776,7 +6776,7 @@ interface DocumentEventMap extends GlobalEventHandlersEventMap { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Document) */ -interface Document extends Node, DocumentOrShadowRoot, FontFaceSource, GlobalEventHandlers, NonElementParentNode, ParentNode, XPathEvaluatorBase { +interface Document extends Node, DocumentOrShadowRoot, FontFaceSource, GlobalEventHandlers, NonElementParentNode, ParentNode, XPathEvaluatorBase { /** * Sets or gets the URL for the current document. * @@ -8988,147 +8988,147 @@ interface GlobalEventHandlersEventMap { "wheel": WheelEvent; } -interface GlobalEventHandlers { +interface GlobalEventHandlers { /** * Fires when the user aborts the download. * @param ev The event. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement/abort_event) */ - onabort: ((this: GlobalEventHandlers, ev: UIEvent) => any) | null; + onabort: ((this: GlobalEventHandlers, ev: UIEvent) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/animationcancel_event) */ - onanimationcancel: ((this: GlobalEventHandlers, ev: AnimationEvent) => any) | null; + onanimationcancel: ((this: GlobalEventHandlers, ev: AnimationEvent) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/animationend_event) */ - onanimationend: ((this: GlobalEventHandlers, ev: AnimationEvent) => any) | null; + onanimationend: ((this: GlobalEventHandlers, ev: AnimationEvent) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/animationiteration_event) */ - onanimationiteration: ((this: GlobalEventHandlers, ev: AnimationEvent) => any) | null; + onanimationiteration: ((this: GlobalEventHandlers, ev: AnimationEvent) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/animationstart_event) */ - onanimationstart: ((this: GlobalEventHandlers, ev: AnimationEvent) => any) | null; + onanimationstart: ((this: GlobalEventHandlers, ev: AnimationEvent) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/auxclick_event) */ - onauxclick: ((this: GlobalEventHandlers, ev: MouseEvent) => any) | null; + onauxclick: ((this: GlobalEventHandlers, ev: MouseEvent) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/beforeinput_event) */ - onbeforeinput: ((this: GlobalEventHandlers, ev: InputEvent) => any) | null; + onbeforeinput: ((this: GlobalEventHandlers, ev: InputEvent) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLElement/beforetoggle_event) */ - onbeforetoggle: ((this: GlobalEventHandlers, ev: Event) => any) | null; + onbeforetoggle: ((this: GlobalEventHandlers, ev: Event) => any) | null; /** * Fires when the object loses the input focus. * @param ev The focus event. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/blur_event) */ - onblur: ((this: GlobalEventHandlers, ev: FocusEvent) => any) | null; + onblur: ((this: GlobalEventHandlers, ev: FocusEvent) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLDialogElement/cancel_event) */ - oncancel: ((this: GlobalEventHandlers, ev: Event) => any) | null; + oncancel: ((this: GlobalEventHandlers, ev: Event) => any) | null; /** * Occurs when playback is possible, but would require further buffering. * @param ev The event. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement/canplay_event) */ - oncanplay: ((this: GlobalEventHandlers, ev: Event) => any) | null; + oncanplay: ((this: GlobalEventHandlers, ev: Event) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement/canplaythrough_event) */ - oncanplaythrough: ((this: GlobalEventHandlers, ev: Event) => any) | null; + oncanplaythrough: ((this: GlobalEventHandlers, ev: Event) => any) | null; /** * Fires when the contents of the object or selection have changed. * @param ev The event. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLElement/change_event) */ - onchange: ((this: GlobalEventHandlers, ev: Event) => any) | null; + onchange: ((this: GlobalEventHandlers, ev: Event) => any) | null; /** * Fires when the user clicks the left mouse button on the object * @param ev The mouse event. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/click_event) */ - onclick: ((this: GlobalEventHandlers, ev: MouseEvent) => any) | null; + onclick: ((this: GlobalEventHandlers, ev: MouseEvent) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLDialogElement/close_event) */ - onclose: ((this: GlobalEventHandlers, ev: Event) => any) | null; + onclose: ((this: GlobalEventHandlers, ev: Event) => any) | null; /** * Fires when the user clicks the right mouse button in the client area, opening the context menu. * @param ev The mouse event. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/contextmenu_event) */ - oncontextmenu: ((this: GlobalEventHandlers, ev: MouseEvent) => any) | null; + oncontextmenu: ((this: GlobalEventHandlers, ev: MouseEvent) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/copy_event) */ - oncopy: ((this: GlobalEventHandlers, ev: ClipboardEvent) => any) | null; + oncopy: ((this: GlobalEventHandlers, ev: ClipboardEvent) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLTrackElement/cuechange_event) */ - oncuechange: ((this: GlobalEventHandlers, ev: Event) => any) | null; + oncuechange: ((this: GlobalEventHandlers, ev: Event) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/cut_event) */ - oncut: ((this: GlobalEventHandlers, ev: ClipboardEvent) => any) | null; + oncut: ((this: GlobalEventHandlers, ev: ClipboardEvent) => any) | null; /** * Fires when the user double-clicks the object. * @param ev The mouse event. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/dblclick_event) */ - ondblclick: ((this: GlobalEventHandlers, ev: MouseEvent) => any) | null; + ondblclick: ((this: GlobalEventHandlers, ev: MouseEvent) => any) | null; /** * Fires on the source object continuously during a drag operation. * @param ev The event. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLElement/drag_event) */ - ondrag: ((this: GlobalEventHandlers, ev: DragEvent) => any) | null; + ondrag: ((this: GlobalEventHandlers, ev: DragEvent) => any) | null; /** * Fires on the source object when the user releases the mouse at the close of a drag operation. * @param ev The event. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLElement/dragend_event) */ - ondragend: ((this: GlobalEventHandlers, ev: DragEvent) => any) | null; + ondragend: ((this: GlobalEventHandlers, ev: DragEvent) => any) | null; /** * Fires on the target element when the user drags the object to a valid drop target. * @param ev The drag event. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLElement/dragenter_event) */ - ondragenter: ((this: GlobalEventHandlers, ev: DragEvent) => any) | null; + ondragenter: ((this: GlobalEventHandlers, ev: DragEvent) => any) | null; /** * Fires on the target object when the user moves the mouse out of a valid drop target during a drag operation. * @param ev The drag event. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLElement/dragleave_event) */ - ondragleave: ((this: GlobalEventHandlers, ev: DragEvent) => any) | null; + ondragleave: ((this: GlobalEventHandlers, ev: DragEvent) => any) | null; /** * Fires on the target element continuously while the user drags the object over a valid drop target. * @param ev The event. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLElement/dragover_event) */ - ondragover: ((this: GlobalEventHandlers, ev: DragEvent) => any) | null; + ondragover: ((this: GlobalEventHandlers, ev: DragEvent) => any) | null; /** * Fires on the source object when the user starts to drag a text selection or selected object. * @param ev The event. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLElement/dragstart_event) */ - ondragstart: ((this: GlobalEventHandlers, ev: DragEvent) => any) | null; + ondragstart: ((this: GlobalEventHandlers, ev: DragEvent) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLElement/drop_event) */ - ondrop: ((this: GlobalEventHandlers, ev: DragEvent) => any) | null; + ondrop: ((this: GlobalEventHandlers, ev: DragEvent) => any) | null; /** * Occurs when the duration attribute is updated. * @param ev The event. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement/durationchange_event) */ - ondurationchange: ((this: GlobalEventHandlers, ev: Event) => any) | null; + ondurationchange: ((this: GlobalEventHandlers, ev: Event) => any) | null; /** * Occurs when the media element is reset to its initial state. * @param ev The event. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement/emptied_event) */ - onemptied: ((this: GlobalEventHandlers, ev: Event) => any) | null; + onemptied: ((this: GlobalEventHandlers, ev: Event) => any) | null; /** * Occurs when the end of playback is reached. * @param ev The event * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement/ended_event) */ - onended: ((this: GlobalEventHandlers, ev: Event) => any) | null; + onended: ((this: GlobalEventHandlers, ev: Event) => any) | null; /** * Fires when an error occurs during object loading. * @param ev The event. @@ -9142,22 +9142,22 @@ interface GlobalEventHandlers { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/focus_event) */ - onfocus: ((this: GlobalEventHandlers, ev: FocusEvent) => any) | null; + onfocus: ((this: GlobalEventHandlers, ev: FocusEvent) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLFormElement/formdata_event) */ - onformdata: ((this: GlobalEventHandlers, ev: FormDataEvent) => any) | null; + onformdata: ((this: GlobalEventHandlers, ev: FormDataEvent) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/gotpointercapture_event) */ - ongotpointercapture: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null; + ongotpointercapture: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/input_event) */ - oninput: ((this: GlobalEventHandlers, ev: Event) => any) | null; + oninput: ((this: GlobalEventHandlers, ev: Event) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLInputElement/invalid_event) */ - oninvalid: ((this: GlobalEventHandlers, ev: Event) => any) | null; + oninvalid: ((this: GlobalEventHandlers, ev: Event) => any) | null; /** * Fires when the user presses a key. * @param ev The keyboard event * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/keydown_event) */ - onkeydown: ((this: GlobalEventHandlers, ev: KeyboardEvent) => any) | null; + onkeydown: ((this: GlobalEventHandlers, ev: KeyboardEvent) => any) | null; /** * Fires when the user presses an alphanumeric key. * @param ev The event. @@ -9165,267 +9165,267 @@ interface GlobalEventHandlers { * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/keypress_event) */ - onkeypress: ((this: GlobalEventHandlers, ev: KeyboardEvent) => any) | null; + onkeypress: ((this: GlobalEventHandlers, ev: KeyboardEvent) => any) | null; /** * Fires when the user releases a key. * @param ev The keyboard event * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/keyup_event) */ - onkeyup: ((this: GlobalEventHandlers, ev: KeyboardEvent) => any) | null; + onkeyup: ((this: GlobalEventHandlers, ev: KeyboardEvent) => any) | null; /** * Fires immediately after the browser loads the object. * @param ev The event. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/SVGElement/load_event) */ - onload: ((this: GlobalEventHandlers, ev: Event) => any) | null; + onload: ((this: GlobalEventHandlers, ev: Event) => any) | null; /** * Occurs when media data is loaded at the current playback position. * @param ev The event. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement/loadeddata_event) */ - onloadeddata: ((this: GlobalEventHandlers, ev: Event) => any) | null; + onloadeddata: ((this: GlobalEventHandlers, ev: Event) => any) | null; /** * Occurs when the duration and dimensions of the media have been determined. * @param ev The event. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement/loadedmetadata_event) */ - onloadedmetadata: ((this: GlobalEventHandlers, ev: Event) => any) | null; + onloadedmetadata: ((this: GlobalEventHandlers, ev: Event) => any) | null; /** * Occurs when Internet Explorer begins looking for media data. * @param ev The event. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement/loadstart_event) */ - onloadstart: ((this: GlobalEventHandlers, ev: Event) => any) | null; + onloadstart: ((this: GlobalEventHandlers, ev: Event) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLElement/lostpointercapture_event) */ - onlostpointercapture: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null; + onlostpointercapture: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null; /** * Fires when the user clicks the object with either mouse button. * @param ev The mouse event. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/mousedown_event) */ - onmousedown: ((this: GlobalEventHandlers, ev: MouseEvent) => any) | null; + onmousedown: ((this: GlobalEventHandlers, ev: MouseEvent) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/mouseenter_event) */ - onmouseenter: ((this: GlobalEventHandlers, ev: MouseEvent) => any) | null; + onmouseenter: ((this: GlobalEventHandlers, ev: MouseEvent) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/mouseleave_event) */ - onmouseleave: ((this: GlobalEventHandlers, ev: MouseEvent) => any) | null; + onmouseleave: ((this: GlobalEventHandlers, ev: MouseEvent) => any) | null; /** * Fires when the user moves the mouse over the object. * @param ev The mouse event. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/mousemove_event) */ - onmousemove: ((this: GlobalEventHandlers, ev: MouseEvent) => any) | null; + onmousemove: ((this: GlobalEventHandlers, ev: MouseEvent) => any) | null; /** * Fires when the user moves the mouse pointer outside the boundaries of the object. * @param ev The mouse event. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/mouseout_event) */ - onmouseout: ((this: GlobalEventHandlers, ev: MouseEvent) => any) | null; + onmouseout: ((this: GlobalEventHandlers, ev: MouseEvent) => any) | null; /** * Fires when the user moves the mouse pointer into the object. * @param ev The mouse event. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/mouseover_event) */ - onmouseover: ((this: GlobalEventHandlers, ev: MouseEvent) => any) | null; + onmouseover: ((this: GlobalEventHandlers, ev: MouseEvent) => any) | null; /** * Fires when the user releases a mouse button while the mouse is over the object. * @param ev The mouse event. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/mouseup_event) */ - onmouseup: ((this: GlobalEventHandlers, ev: MouseEvent) => any) | null; + onmouseup: ((this: GlobalEventHandlers, ev: MouseEvent) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/paste_event) */ - onpaste: ((this: GlobalEventHandlers, ev: ClipboardEvent) => any) | null; + onpaste: ((this: GlobalEventHandlers, ev: ClipboardEvent) => any) | null; /** * Occurs when playback is paused. * @param ev The event. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement/pause_event) */ - onpause: ((this: GlobalEventHandlers, ev: Event) => any) | null; + onpause: ((this: GlobalEventHandlers, ev: Event) => any) | null; /** * Occurs when the play method is requested. * @param ev The event. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement/play_event) */ - onplay: ((this: GlobalEventHandlers, ev: Event) => any) | null; + onplay: ((this: GlobalEventHandlers, ev: Event) => any) | null; /** * Occurs when the audio or video has started playing. * @param ev The event. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement/playing_event) */ - onplaying: ((this: GlobalEventHandlers, ev: Event) => any) | null; + onplaying: ((this: GlobalEventHandlers, ev: Event) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/pointercancel_event) */ - onpointercancel: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null; + onpointercancel: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/pointerdown_event) */ - onpointerdown: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null; + onpointerdown: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/pointerenter_event) */ - onpointerenter: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null; + onpointerenter: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/pointerleave_event) */ - onpointerleave: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null; + onpointerleave: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/pointermove_event) */ - onpointermove: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null; + onpointermove: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/pointerout_event) */ - onpointerout: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null; + onpointerout: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/pointerover_event) */ - onpointerover: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null; + onpointerover: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/pointerup_event) */ - onpointerup: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null; + onpointerup: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null; /** * Occurs to indicate progress while downloading media data. * @param ev The event. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement/progress_event) */ - onprogress: ((this: GlobalEventHandlers, ev: ProgressEvent) => any) | null; + onprogress: ((this: GlobalEventHandlers, ev: ProgressEvent) => any) | null; /** * Occurs when the playback rate is increased or decreased. * @param ev The event. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement/ratechange_event) */ - onratechange: ((this: GlobalEventHandlers, ev: Event) => any) | null; + onratechange: ((this: GlobalEventHandlers, ev: Event) => any) | null; /** * Fires when the user resets a form. * @param ev The event. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLFormElement/reset_event) */ - onreset: ((this: GlobalEventHandlers, ev: Event) => any) | null; + onreset: ((this: GlobalEventHandlers, ev: Event) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLVideoElement/resize_event) */ - onresize: ((this: GlobalEventHandlers, ev: UIEvent) => any) | null; + onresize: ((this: GlobalEventHandlers, ev: UIEvent) => any) | null; /** * Fires when the user repositions the scroll box in the scroll bar on the object. * @param ev The event. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Document/scroll_event) */ - onscroll: ((this: GlobalEventHandlers, ev: Event) => any) | null; + onscroll: ((this: GlobalEventHandlers, ev: Event) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Document/scrollend_event) */ - onscrollend: ((this: GlobalEventHandlers, ev: Event) => any) | null; + onscrollend: ((this: GlobalEventHandlers, ev: Event) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Document/securitypolicyviolation_event) */ - onsecuritypolicyviolation: ((this: GlobalEventHandlers, ev: SecurityPolicyViolationEvent) => any) | null; + onsecuritypolicyviolation: ((this: GlobalEventHandlers, ev: SecurityPolicyViolationEvent) => any) | null; /** * Occurs when the seek operation ends. * @param ev The event. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement/seeked_event) */ - onseeked: ((this: GlobalEventHandlers, ev: Event) => any) | null; + onseeked: ((this: GlobalEventHandlers, ev: Event) => any) | null; /** * Occurs when the current playback position is moved. * @param ev The event. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement/seeking_event) */ - onseeking: ((this: GlobalEventHandlers, ev: Event) => any) | null; + onseeking: ((this: GlobalEventHandlers, ev: Event) => any) | null; /** * Fires when the current selection changes. * @param ev The event. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLInputElement/select_event) */ - onselect: ((this: GlobalEventHandlers, ev: Event) => any) | null; + onselect: ((this: GlobalEventHandlers, ev: Event) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Document/selectionchange_event) */ - onselectionchange: ((this: GlobalEventHandlers, ev: Event) => any) | null; + onselectionchange: ((this: GlobalEventHandlers, ev: Event) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Node/selectstart_event) */ - onselectstart: ((this: GlobalEventHandlers, ev: Event) => any) | null; + onselectstart: ((this: GlobalEventHandlers, ev: Event) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLSlotElement/slotchange_event) */ - onslotchange: ((this: GlobalEventHandlers, ev: Event) => any) | null; + onslotchange: ((this: GlobalEventHandlers, ev: Event) => any) | null; /** * Occurs when the download has stopped. * @param ev The event. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement/stalled_event) */ - onstalled: ((this: GlobalEventHandlers, ev: Event) => any) | null; + onstalled: ((this: GlobalEventHandlers, ev: Event) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLFormElement/submit_event) */ - onsubmit: ((this: GlobalEventHandlers, ev: SubmitEvent) => any) | null; + onsubmit: ((this: GlobalEventHandlers, ev: SubmitEvent) => any) | null; /** * Occurs if the load operation has been intentionally halted. * @param ev The event. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement/suspend_event) */ - onsuspend: ((this: GlobalEventHandlers, ev: Event) => any) | null; + onsuspend: ((this: GlobalEventHandlers, ev: Event) => any) | null; /** * Occurs to indicate the current playback position. * @param ev The event. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement/timeupdate_event) */ - ontimeupdate: ((this: GlobalEventHandlers, ev: Event) => any) | null; + ontimeupdate: ((this: GlobalEventHandlers, ev: Event) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLDetailsElement/toggle_event) */ - ontoggle: ((this: GlobalEventHandlers, ev: Event) => any) | null; + ontoggle: ((this: GlobalEventHandlers, ev: Event) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/touchcancel_event) */ - ontouchcancel?: ((this: GlobalEventHandlers, ev: TouchEvent) => any) | null | undefined; + ontouchcancel?: ((this: GlobalEventHandlers, ev: TouchEvent) => any) | null | undefined; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/touchend_event) */ - ontouchend?: ((this: GlobalEventHandlers, ev: TouchEvent) => any) | null | undefined; + ontouchend?: ((this: GlobalEventHandlers, ev: TouchEvent) => any) | null | undefined; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/touchmove_event) */ - ontouchmove?: ((this: GlobalEventHandlers, ev: TouchEvent) => any) | null | undefined; + ontouchmove?: ((this: GlobalEventHandlers, ev: TouchEvent) => any) | null | undefined; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/touchstart_event) */ - ontouchstart?: ((this: GlobalEventHandlers, ev: TouchEvent) => any) | null | undefined; + ontouchstart?: ((this: GlobalEventHandlers, ev: TouchEvent) => any) | null | undefined; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/transitioncancel_event) */ - ontransitioncancel: ((this: GlobalEventHandlers, ev: TransitionEvent) => any) | null; + ontransitioncancel: ((this: GlobalEventHandlers, ev: TransitionEvent) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/transitionend_event) */ - ontransitionend: ((this: GlobalEventHandlers, ev: TransitionEvent) => any) | null; + ontransitionend: ((this: GlobalEventHandlers, ev: TransitionEvent) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/transitionrun_event) */ - ontransitionrun: ((this: GlobalEventHandlers, ev: TransitionEvent) => any) | null; + ontransitionrun: ((this: GlobalEventHandlers, ev: TransitionEvent) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/transitionstart_event) */ - ontransitionstart: ((this: GlobalEventHandlers, ev: TransitionEvent) => any) | null; + ontransitionstart: ((this: GlobalEventHandlers, ev: TransitionEvent) => any) | null; /** * Occurs when the volume is changed, or playback is muted or unmuted. * @param ev The event. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement/volumechange_event) */ - onvolumechange: ((this: GlobalEventHandlers, ev: Event) => any) | null; + onvolumechange: ((this: GlobalEventHandlers, ev: Event) => any) | null; /** * Occurs when playback stops because the next frame of a video resource is not available. * @param ev The event. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement/waiting_event) */ - onwaiting: ((this: GlobalEventHandlers, ev: Event) => any) | null; + onwaiting: ((this: GlobalEventHandlers, ev: Event) => any) | null; /** * @deprecated This is a legacy alias of `onanimationend`. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/animationend_event) */ - onwebkitanimationend: ((this: GlobalEventHandlers, ev: Event) => any) | null; + onwebkitanimationend: ((this: GlobalEventHandlers, ev: Event) => any) | null; /** * @deprecated This is a legacy alias of `onanimationiteration`. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/animationiteration_event) */ - onwebkitanimationiteration: ((this: GlobalEventHandlers, ev: Event) => any) | null; + onwebkitanimationiteration: ((this: GlobalEventHandlers, ev: Event) => any) | null; /** * @deprecated This is a legacy alias of `onanimationstart`. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/animationstart_event) */ - onwebkitanimationstart: ((this: GlobalEventHandlers, ev: Event) => any) | null; + onwebkitanimationstart: ((this: GlobalEventHandlers, ev: Event) => any) | null; /** * @deprecated This is a legacy alias of `ontransitionend`. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/transitionend_event) */ - onwebkittransitionend: ((this: GlobalEventHandlers, ev: Event) => any) | null; + onwebkittransitionend: ((this: GlobalEventHandlers, ev: Event) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/wheel_event) */ - onwheel: ((this: GlobalEventHandlers, ev: WheelEvent) => any) | null; - addEventListener(type: K, listener: (this: GlobalEventHandlers, ev: GlobalEventHandlersEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; + onwheel: ((this: GlobalEventHandlers, ev: WheelEvent) => any) | null; + addEventListener(type: K, listener: (this: GlobalEventHandlers, ev: GlobalEventHandlersEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void; - removeEventListener(type: K, listener: (this: GlobalEventHandlers, ev: GlobalEventHandlersEventMap[K]) => any, options?: boolean | EventListenerOptions): void; + removeEventListener(type: K, listener: (this: GlobalEventHandlers, ev: GlobalEventHandlersEventMap[K]) => any, options?: boolean | EventListenerOptions): void; removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void; } @@ -10103,7 +10103,7 @@ interface HTMLElementEventMap extends ElementEventMap, GlobalEventHandlersEventM * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLElement) */ -interface HTMLElement extends Element, ElementCSSInlineStyle, ElementContentEditable, GlobalEventHandlers, HTMLOrSVGElement { +interface HTMLElement extends Element, ElementCSSInlineStyle, ElementContentEditable, GlobalEventHandlers, HTMLOrSVGElement { /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLElement/accessKey) */ accessKey: string; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLElement/accessKeyLabel) */ @@ -14973,7 +14973,7 @@ interface MathMLElementEventMap extends ElementEventMap, GlobalEventHandlersEven } /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/MathMLElement) */ -interface MathMLElement extends Element, ElementCSSInlineStyle, GlobalEventHandlers, HTMLOrSVGElement { +interface MathMLElement extends Element, ElementCSSInlineStyle, GlobalEventHandlers, HTMLOrSVGElement { addEventListener(type: K, listener: (this: MathMLElement, ev: MathMLElementEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void; removeEventListener(type: K, listener: (this: MathMLElement, ev: MathMLElementEventMap[K]) => any, options?: boolean | EventListenerOptions): void; @@ -19477,7 +19477,7 @@ interface SVGElementEventMap extends ElementEventMap, GlobalEventHandlersEventMa * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/SVGElement) */ -interface SVGElement extends Element, ElementCSSInlineStyle, GlobalEventHandlers, HTMLOrSVGElement { +interface SVGElement extends Element, ElementCSSInlineStyle, GlobalEventHandlers, HTMLOrSVGElement { /** @deprecated */ readonly className: any; readonly ownerSVGElement: SVGSVGElement | null; @@ -25840,7 +25840,7 @@ interface WindowEventMap extends GlobalEventHandlersEventMap, WindowEventHandler * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window) */ -interface Window extends EventTarget, AnimationFrameProvider, GlobalEventHandlers, WindowEventHandlers, WindowLocalStorage, WindowOrWorkerGlobalScope, WindowSessionStorage { +interface Window extends EventTarget, AnimationFrameProvider, GlobalEventHandlers, WindowEventHandlers, WindowLocalStorage, WindowOrWorkerGlobalScope, WindowSessionStorage { /** * @deprecated This is a legacy alias of `navigator`. * diff --git a/inputfiles/addedTypes.jsonc b/inputfiles/addedTypes.jsonc index 7f16b1401..6f28cc55e 100644 --- a/inputfiles/addedTypes.jsonc +++ b/inputfiles/addedTypes.jsonc @@ -50,6 +50,13 @@ } }, "GlobalEventHandlers": { + "typeParameters": [ + { + "name": "T", + "default": "EventTarget", + "extends": "EventTarget" + } + ], "events": { "event": [ { diff --git a/src/build/emitter.ts b/src/build/emitter.ts index 127ce4d5c..0cc9efec1 100644 --- a/src/build/emitter.ts +++ b/src/build/emitter.ts @@ -318,9 +318,25 @@ export function emitWebIdl( return distinct(mixinsWithConstant); } - function getEventTypeInInterface(eName: string, i: Browser.Interface) { + function getEventTypeInInterface( + eName: string, + i: Browser.Interface, + specifyEventTypeParameter = false, + ) { function getGenericEventType(baseName: string) { - if (baseName === "ProgressEvent" && !i.mixin) { + if ( + specifyEventTypeParameter && + genericEventSupertypes.has(baseName) && + i.typeParameters?.some((typeParameter) => typeParameter.name === "T") + ) { + return `${baseName}`; + } + + if ( + (genericEventSupertypes.has(baseName) || + baseName === "ProgressEvent") && + !i.mixin + ) { return `${baseName}<${i.name}>`; } return baseName; @@ -797,7 +813,11 @@ export function emitWebIdl( // events in different interfaces. For example, "onerror" handles "ErrorEvent" // normally, but in "SVGSVGElement" it handles "SVGError" event instead. const eType = p.eventHandler - ? getEventTypeInInterface(p.eventHandler!, i) + ? getEventTypeInInterface( + p.eventHandler!, + i, + emitScope === EmitScope.InstanceOnly, + ) : "Event"; pType = `(${emitEventHandlerThis(prefix, i)}ev: ${eType}) => any`; if (typeof p.type === "string" && !p.type.endsWith("NonNull")) { @@ -1187,6 +1207,8 @@ export function emitWebIdl( function emitInterfaceDeclaration(i: Browser.Interface) { function processIName(iName: string) { + if (iName === "GlobalEventHandlers" && i.name !== iName) + return `${iName}<${i.name}>`; return extendConflictsBaseTypes[iName] ? `${iName}Base` : iName; }