Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic DOM Events #1624

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions baselines/audioworklet.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ declare var ErrorEvent: {
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event)
*/
interface Event {
interface Event<T extends EventTarget = EventTarget> {
/**
* 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.
*
Expand Down Expand Up @@ -465,7 +465,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.
*
Expand Down Expand Up @@ -559,12 +559,12 @@ declare var Event: {
readonly BUBBLING_PHASE: 3;
};

interface EventListener {
(evt: Event): void;
interface EventListener<T extends EventTarget = EventTarget> {
(evt: Event<T>): void;
}

interface EventListenerObject {
handleEvent(object: Event): void;
interface EventListenerObject<T extends EventTarget = EventTarget> {
handleEvent(object: Event<T>): void;
}

/**
Expand All @@ -590,7 +590,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<this> | 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.
*
Expand All @@ -602,7 +602,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<this> | null, options?: EventListenerOptions | boolean): void;
}

declare var EventTarget: {
Expand Down Expand Up @@ -1408,7 +1408,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<T extends EventTarget = EventTarget> = EventListener<T> | EventListenerObject<T>;
type MessageEventSource = MessagePort;
type ReadableStreamController<T> = ReadableStreamDefaultController<T> | ReadableByteStreamController;
type ReadableStreamReadResult<T> = ReadableStreamReadValueResult<T> | ReadableStreamReadDoneResult<T>;
Expand Down
244 changes: 122 additions & 122 deletions baselines/dom.generated.d.ts

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions baselines/serviceworker.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2197,7 +2197,7 @@ declare var ErrorEvent: {
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event)
*/
interface Event {
interface Event<T extends EventTarget = EventTarget> {
/**
* 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.
*
Expand Down Expand Up @@ -2227,7 +2227,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.
*
Expand Down Expand Up @@ -2321,12 +2321,12 @@ declare var Event: {
readonly BUBBLING_PHASE: 3;
};

interface EventListener {
(evt: Event): void;
interface EventListener<T extends EventTarget = EventTarget> {
(evt: Event<T>): void;
}

interface EventListenerObject {
handleEvent(object: Event): void;
interface EventListenerObject<T extends EventTarget = EventTarget> {
handleEvent(object: Event<T>): void;
}

interface EventSourceEventMap {
Expand Down Expand Up @@ -2409,7 +2409,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<this> | 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.
*
Expand All @@ -2421,7 +2421,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<this> | null, options?: EventListenerOptions | boolean): void;
}

declare var EventTarget: {
Expand Down Expand Up @@ -8550,7 +8550,7 @@ type CSSUnparsedSegment = string | CSSVariableReferenceValue;
type CanvasImageSource = ImageBitmap | OffscreenCanvas;
type DOMHighResTimeStamp = number;
type EpochTimeStamp = number;
type EventListenerOrEventListenerObject = EventListener | EventListenerObject;
type EventListenerOrEventListenerObject<T extends EventTarget = EventTarget> = EventListener<T> | EventListenerObject<T>;
type FileSystemWriteChunkType = BufferSource | Blob | string | WriteParams;
type Float32List = Float32Array | GLfloat[];
type FormDataEntryValue = File | string;
Expand Down
18 changes: 9 additions & 9 deletions baselines/sharedworker.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2124,7 +2124,7 @@ declare var ErrorEvent: {
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event)
*/
interface Event {
interface Event<T extends EventTarget = EventTarget> {
/**
* 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.
*
Expand Down Expand Up @@ -2154,7 +2154,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.
*
Expand Down Expand Up @@ -2248,12 +2248,12 @@ declare var Event: {
readonly BUBBLING_PHASE: 3;
};

interface EventListener {
(evt: Event): void;
interface EventListener<T extends EventTarget = EventTarget> {
(evt: Event<T>): void;
}

interface EventListenerObject {
handleEvent(object: Event): void;
interface EventListenerObject<T extends EventTarget = EventTarget> {
handleEvent(object: Event<T>): void;
}

interface EventSourceEventMap {
Expand Down Expand Up @@ -2336,7 +2336,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<this> | 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.
*
Expand All @@ -2348,7 +2348,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<this> | null, options?: EventListenerOptions | boolean): void;
}

declare var EventTarget: {
Expand Down Expand Up @@ -8557,7 +8557,7 @@ type CSSUnparsedSegment = string | CSSVariableReferenceValue;
type CanvasImageSource = ImageBitmap | OffscreenCanvas;
type DOMHighResTimeStamp = number;
type EpochTimeStamp = number;
type EventListenerOrEventListenerObject = EventListener | EventListenerObject;
type EventListenerOrEventListenerObject<T extends EventTarget = EventTarget> = EventListener<T> | EventListenerObject<T>;
type FileSystemWriteChunkType = BufferSource | Blob | string | WriteParams;
type Float32List = Float32Array | GLfloat[];
type FormDataEntryValue = File | string;
Expand Down
18 changes: 9 additions & 9 deletions baselines/webworker.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2407,7 +2407,7 @@ declare var ErrorEvent: {
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event)
*/
interface Event {
interface Event<T extends EventTarget = EventTarget> {
/**
* 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.
*
Expand Down Expand Up @@ -2437,7 +2437,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.
*
Expand Down Expand Up @@ -2531,12 +2531,12 @@ declare var Event: {
readonly BUBBLING_PHASE: 3;
};

interface EventListener {
(evt: Event): void;
interface EventListener<T extends EventTarget = EventTarget> {
(evt: Event<T>): void;
}

interface EventListenerObject {
handleEvent(object: Event): void;
interface EventListenerObject<T extends EventTarget = EventTarget> {
handleEvent(object: Event<T>): void;
}

interface EventSourceEventMap {
Expand Down Expand Up @@ -2619,7 +2619,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<this> | 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.
*
Expand All @@ -2631,7 +2631,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<this> | null, options?: EventListenerOptions | boolean): void;
}

declare var EventTarget: {
Expand Down Expand Up @@ -9283,7 +9283,7 @@ type CSSUnparsedSegment = string | CSSVariableReferenceValue;
type CanvasImageSource = ImageBitmap | OffscreenCanvas | VideoFrame;
type DOMHighResTimeStamp = number;
type EpochTimeStamp = number;
type EventListenerOrEventListenerObject = EventListener | EventListenerObject;
type EventListenerOrEventListenerObject<T extends EventTarget = EventTarget> = EventListener<T> | EventListenerObject<T>;
type FileSystemWriteChunkType = BufferSource | Blob | string | WriteParams;
type Float32List = Float32Array | GLfloat[];
type FormDataEntryValue = File | string;
Expand Down
60 changes: 57 additions & 3 deletions inputfiles/addedTypes.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@
}
},
"GlobalEventHandlers": {
"typeParameters": [
{
"name": "T",
"default": "EventTarget",
"extends": "EventTarget"
}
],
"events": {
"event": [
{
Expand Down Expand Up @@ -768,6 +775,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
Expand All @@ -776,14 +801,21 @@
"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
// as it means we don't have to add a call signatures section to the
// emitter for this one case.
"callable": {
"overrideSignatures": [
"(evt: Event): void"
"(evt: Event<T>): void"
]
}
}
Expand All @@ -792,11 +824,18 @@
"EventListenerObject": {
"name": "EventListenerObject",
"noInterfaceObject": true,
"typeParameters": [
{
"name": "T",
"default": "EventTarget",
"extends": "EventTarget"
}
],
"methods": {
"method": {
"handleEvent": {
"overrideSignatures": [
"handleEvent(object: Event): void"
"handleEvent(object: Event<T>): void"
]
}
}
Expand Down Expand Up @@ -920,6 +959,14 @@
}
},
"UIEvent": {
"extends": "Event<T>",
"typeParameters": [
{
"name": "T",
"default": "EventTarget",
"extends": "EventTarget"
}
],
"properties": {
"property": {
"which": {
Expand Down Expand Up @@ -1539,7 +1586,14 @@
},
{
"name": "EventListenerOrEventListenerObject",
"overrideType": "EventListener | EventListenerObject"
"overrideType": "EventListener<T> | EventListenerObject<T>",
"typeParameters": [
{
"name": "T",
"default": "EventTarget",
"extends": "EventTarget"
}
]
},
{
"name": "OptionalPrefixToken",
Expand Down
4 changes: 2 additions & 2 deletions inputfiles/overridingTypes.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -3002,7 +3002,7 @@
"param": [
{
"name": "callback",
"overrideType": "EventListenerOrEventListenerObject"
"overrideType": "EventListenerOrEventListenerObject<this>"
nscarcella marked this conversation as resolved.
Show resolved Hide resolved
}
]
}
Expand All @@ -3014,7 +3014,7 @@
"param": [
{
"name": "callback",
"overrideType": "EventListenerOrEventListenerObject"
"overrideType": "EventListenerOrEventListenerObject<this>"
}
]
}
Expand Down
Loading
Loading