-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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
node: Backport #59905 to ts4.8 #62629
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
export {}; // Don't export anything! | ||
|
||
//// DOM-like Events | ||
// NB: The Event / EventTarget / EventListener implementations below were copied | ||
// from lib.dom.d.ts, then edited to reflect Node's documentation at | ||
// https://nodejs.org/api/events.html#class-eventtarget. | ||
// Please read that link to understand important implementation differences. | ||
|
||
// This conditional type will be the existing global Event in a browser, or | ||
// the copy below in a Node environment. | ||
type __Event = typeof globalThis extends { onmessage: any, Event: infer T } | ||
? T | ||
: { | ||
/** This is not used in Node.js and is provided purely for completeness. */ | ||
readonly bubbles: boolean; | ||
/** Alias for event.stopPropagation(). This is not used in Node.js and is provided purely for completeness. */ | ||
cancelBubble: () => void; | ||
/** True if the event was created with the cancelable option */ | ||
readonly cancelable: boolean; | ||
/** This is not used in Node.js and is provided purely for completeness. */ | ||
readonly composed: boolean; | ||
/** Returns an array containing the current EventTarget as the only entry or empty if the event is not being dispatched. This is not used in Node.js and is provided purely for completeness. */ | ||
composedPath(): [EventTarget?] | ||
/** Alias for event.target. */ | ||
readonly currentTarget: EventTarget | null; | ||
/** Is true if cancelable is true and event.preventDefault() has been called. */ | ||
readonly defaultPrevented: boolean; | ||
/** This is not used in Node.js and is provided purely for completeness. */ | ||
readonly eventPhase: 0 | 2; | ||
/** The `AbortSignal` "abort" event is emitted with `isTrusted` set to `true`. The value is `false` in all other cases. */ | ||
readonly isTrusted: boolean; | ||
/** Sets the `defaultPrevented` property to `true` if `cancelable` is `true`. */ | ||
preventDefault(): void; | ||
/** This is not used in Node.js and is provided purely for completeness. */ | ||
returnValue: boolean; | ||
/** Alias for event.target. */ | ||
readonly srcElement: EventTarget | null; | ||
/** Stops the invocation of event listeners after the current one completes. */ | ||
stopImmediatePropagation(): void; | ||
/** This is not used in Node.js and is provided purely for completeness. */ | ||
stopPropagation(): void; | ||
/** The `EventTarget` dispatching the event */ | ||
readonly target: EventTarget | null; | ||
/** The millisecond timestamp when the Event object was created. */ | ||
readonly timeStamp: number; | ||
/** Returns the type of event, e.g. "click", "hashchange", or "submit". */ | ||
readonly type: string; | ||
}; | ||
|
||
// See comment above explaining conditional type | ||
type __EventTarget = typeof globalThis extends { onmessage: any, EventTarget: infer T } | ||
? T | ||
: { | ||
/** | ||
* Adds a new handler for the `type` event. Any given `listener` is added only once per `type` and per `capture` option value. | ||
* | ||
* If the `once` option is true, the `listener` is removed after the next time a `type` event is dispatched. | ||
* | ||
* The `capture` option is not used by Node.js in any functional way other than tracking registered event listeners per the `EventTarget` specification. | ||
* Specifically, the `capture` option is used as part of the key when registering a `listener`. | ||
* Any individual `listener` may be added once with `capture = false`, and once with `capture = true`. | ||
*/ | ||
addEventListener( | ||
type: string, | ||
listener: EventListener | EventListenerObject, | ||
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. */ | ||
dispatchEvent(event: Event): boolean; | ||
/** Removes the event listener in target's event listener list with the same type, callback, and options. */ | ||
removeEventListener( | ||
type: string, | ||
listener: EventListener | EventListenerObject, | ||
options?: EventListenerOptions | boolean, | ||
): void; | ||
}; | ||
|
||
interface EventInit { | ||
bubbles?: boolean; | ||
cancelable?: boolean; | ||
composed?: boolean; | ||
} | ||
|
||
interface EventListenerOptions { | ||
/** Not directly used by Node.js. Added for API completeness. Default: `false`. */ | ||
capture?: boolean; | ||
} | ||
|
||
interface AddEventListenerOptions extends EventListenerOptions { | ||
/** When `true`, the listener is automatically removed when it is first invoked. Default: `false`. */ | ||
once?: boolean; | ||
/** When `true`, serves as a hint that the listener will not call the `Event` object's `preventDefault()` method. Default: false. */ | ||
passive?: boolean; | ||
} | ||
|
||
interface EventListener { | ||
(evt: Event): void; | ||
} | ||
|
||
interface EventListenerObject { | ||
handleEvent(object: Event): void; | ||
} | ||
|
||
import {} from 'events'; // Make this an ambient declaration | ||
declare global { | ||
/** An event which takes place in the DOM. */ | ||
interface Event extends __Event {} | ||
var Event: typeof globalThis extends { onmessage: any, Event: infer T } | ||
? T | ||
: { | ||
prototype: __Event; | ||
new (type: string, eventInitDict?: EventInit): __Event; | ||
}; | ||
|
||
/** | ||
* EventTarget is a DOM interface implemented by objects that can | ||
* receive events and may have listeners for them. | ||
*/ | ||
interface EventTarget extends __EventTarget {} | ||
var EventTarget: typeof globalThis extends { onmessage: any, EventTarget: infer T } | ||
? T | ||
: { | ||
prototype: __EventTarget; | ||
new (): __EventTarget; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe
T['prototype']
?