From d632cce129cb7025a34cf0aa7262a38fb12f47c4 Mon Sep 17 00:00:00 2001 From: ud2 Date: Tue, 4 Jul 2023 02:36:55 +0800 Subject: fix(dts): make globals available on globalThis (#19438) This PR changes Web IDL interfaces to be declared with `var` instead of `class`, so that accessing them via `globalThis` does not raise type errors. Closes #13390. --- ext/web/lib.deno_web.d.ts | 426 +++++++++++++++++++++++++++++++++------------- 1 file changed, 309 insertions(+), 117 deletions(-) (limited to 'ext/web') diff --git a/ext/web/lib.deno_web.d.ts b/ext/web/lib.deno_web.d.ts index e1ffdc329..331c9536b 100644 --- a/ext/web/lib.deno_web.d.ts +++ b/ext/web/lib.deno_web.d.ts @@ -5,16 +5,71 @@ /// /// -/** @category DOM Events */ -declare class DOMException extends Error { - constructor(message?: string, name?: string); +/** @category Web APIs */ +declare interface DOMException extends Error { readonly name: string; readonly message: string; readonly code: number; + readonly INDEX_SIZE_ERR: 1; + readonly DOMSTRING_SIZE_ERR: 2; + readonly HIERARCHY_REQUEST_ERR: 3; + readonly WRONG_DOCUMENT_ERR: 4; + readonly INVALID_CHARACTER_ERR: 5; + readonly NO_DATA_ALLOWED_ERR: 6; + readonly NO_MODIFICATION_ALLOWED_ERR: 7; + readonly NOT_FOUND_ERR: 8; + readonly NOT_SUPPORTED_ERR: 9; + readonly INUSE_ATTRIBUTE_ERR: 10; + readonly INVALID_STATE_ERR: 11; + readonly SYNTAX_ERR: 12; + readonly INVALID_MODIFICATION_ERR: 13; + readonly NAMESPACE_ERR: 14; + readonly INVALID_ACCESS_ERR: 15; + readonly VALIDATION_ERR: 16; + readonly TYPE_MISMATCH_ERR: 17; + readonly SECURITY_ERR: 18; + readonly NETWORK_ERR: 19; + readonly ABORT_ERR: 20; + readonly URL_MISMATCH_ERR: 21; + readonly QUOTA_EXCEEDED_ERR: 22; + readonly TIMEOUT_ERR: 23; + readonly INVALID_NODE_TYPE_ERR: 24; + readonly DATA_CLONE_ERR: 25; } +/** @category Web APIs */ +declare var DOMException: { + readonly prototype: DOMException; + new (message?: string, name?: string): DOMException; + readonly INDEX_SIZE_ERR: 1; + readonly DOMSTRING_SIZE_ERR: 2; + readonly HIERARCHY_REQUEST_ERR: 3; + readonly WRONG_DOCUMENT_ERR: 4; + readonly INVALID_CHARACTER_ERR: 5; + readonly NO_DATA_ALLOWED_ERR: 6; + readonly NO_MODIFICATION_ALLOWED_ERR: 7; + readonly NOT_FOUND_ERR: 8; + readonly NOT_SUPPORTED_ERR: 9; + readonly INUSE_ATTRIBUTE_ERR: 10; + readonly INVALID_STATE_ERR: 11; + readonly SYNTAX_ERR: 12; + readonly INVALID_MODIFICATION_ERR: 13; + readonly NAMESPACE_ERR: 14; + readonly INVALID_ACCESS_ERR: 15; + readonly VALIDATION_ERR: 16; + readonly TYPE_MISMATCH_ERR: 17; + readonly SECURITY_ERR: 18; + readonly NETWORK_ERR: 19; + readonly ABORT_ERR: 20; + readonly URL_MISMATCH_ERR: 21; + readonly QUOTA_EXCEEDED_ERR: 22; + readonly TIMEOUT_ERR: 23; + readonly INVALID_NODE_TYPE_ERR: 24; + readonly DATA_CLONE_ERR: 25; +}; + /** @category DOM Events */ -interface EventInit { +declare interface EventInit { bubbles?: boolean; cancelable?: boolean; composed?: boolean; @@ -24,8 +79,7 @@ interface EventInit { * * @category DOM Events */ -declare class Event { - constructor(type: string, eventInitDict?: EventInit); +declare 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. */ @@ -80,19 +134,28 @@ declare class Event { readonly BUBBLING_PHASE: number; readonly CAPTURING_PHASE: number; readonly NONE: number; - static readonly AT_TARGET: number; - static readonly BUBBLING_PHASE: number; - static readonly CAPTURING_PHASE: number; - static readonly NONE: number; } +/** An event which takes place in the DOM. + * + * @category DOM Events + */ +declare var Event: { + readonly prototype: Event; + new (type: string, eventInitDict?: EventInit): Event; + readonly AT_TARGET: number; + readonly BUBBLING_PHASE: number; + readonly CAPTURING_PHASE: number; + readonly NONE: number; +}; + /** * EventTarget is a DOM interface implemented by objects that can receive events * and may have listeners for them. * * @category DOM Events */ -declare class EventTarget { +declare interface EventTarget { /** Appends an event listener for events whose type attribute value is type. * The callback argument sets the callback that will be invoked when the event * is dispatched. @@ -134,13 +197,24 @@ declare class EventTarget { ): void; } +/** + * EventTarget is a DOM interface implemented by objects that can receive events + * and may have listeners for them. + * + * @category DOM Events + */ +declare var EventTarget: { + readonly prototype: EventTarget; + new (): EventTarget; +}; + /** @category DOM Events */ -interface EventListener { +declare interface EventListener { (evt: Event): void | Promise; } /** @category DOM Events */ -interface EventListenerObject { +declare interface EventListenerObject { handleEvent(evt: Event): void | Promise; } @@ -150,19 +224,19 @@ declare type EventListenerOrEventListenerObject = | EventListenerObject; /** @category DOM Events */ -interface AddEventListenerOptions extends EventListenerOptions { +declare interface AddEventListenerOptions extends EventListenerOptions { once?: boolean; passive?: boolean; signal?: AbortSignal; } /** @category DOM Events */ -interface EventListenerOptions { +declare interface EventListenerOptions { capture?: boolean; } /** @category DOM Events */ -interface ProgressEventInit extends EventInit { +declare interface ProgressEventInit extends EventInit { lengthComputable?: boolean; loaded?: number; total?: number; @@ -174,14 +248,25 @@ interface ProgressEventInit extends EventInit { * * @category DOM Events */ -declare class ProgressEvent extends Event { - constructor(type: string, eventInitDict?: ProgressEventInit); +declare interface ProgressEvent + extends Event { readonly lengthComputable: boolean; readonly loaded: number; readonly target: T | null; readonly total: number; } +/** Events measuring progress of an underlying process, like an HTTP request + * (for an XMLHttpRequest, or the loading of the underlying resource of an + * ,