From d632cce129cb7025a34cf0aa7262a38fb12f47c4 Mon Sep 17 00:00:00 2001 From: ud2 Date: Tue, 4 Jul 2023 02:36:55 +0800 Subject: [PATCH] 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. --- cli/tests/integration/lsp_tests.rs | 2 +- cli/tests/unit/cache_api_test.ts | 1 - cli/tsc/dts/lib.deno.shared_globals.d.ts | 120 +++-- cli/tsc/dts/lib.deno.unstable.d.ts | 13 +- cli/tsc/dts/lib.deno.window.d.ts | 40 +- cli/tsc/dts/lib.deno.worker.d.ts | 46 +- cli/tsc/dts/lib.dom.extras.d.ts | 59 ++- .../lib.deno_broadcast_channel.d.ts | 6 +- ext/cache/lib.deno_cache.d.ts | 10 +- ext/crypto/lib.deno_crypto.d.ts | 93 ++-- ext/fetch/lib.deno_fetch.d.ts | 183 +++----- ext/url/lib.deno_url.d.ts | 88 +++- ext/web/lib.deno_web.d.ts | 426 +++++++++++++----- ext/websocket/lib.deno_websocket.d.ts | 35 +- ext/webstorage/lib.deno_webstorage.d.ts | 6 +- 15 files changed, 735 insertions(+), 393 deletions(-) diff --git a/cli/tests/integration/lsp_tests.rs b/cli/tests/integration/lsp_tests.rs index d6a8b4757c..b4339679f5 100644 --- a/cli/tests/integration/lsp_tests.rs +++ b/cli/tests/integration/lsp_tests.rs @@ -4788,7 +4788,7 @@ fn lsp_completions_auto_import() { "source": "./b.ts", "data": { "exportName": "foo", - "exportMapKey": "foo|6820|file:///a/b", + "exportMapKey": "foo|6893|file:///a/b", "moduleSpecifier": "./b.ts", "fileName": "file:///a/b.ts" }, diff --git a/cli/tests/unit/cache_api_test.ts b/cli/tests/unit/cache_api_test.ts index 2f807de448..c1bd7031e9 100644 --- a/cli/tests/unit/cache_api_test.ts +++ b/cli/tests/unit/cache_api_test.ts @@ -97,7 +97,6 @@ Deno.test(async function cacheApi() { }); Deno.test(function cacheIllegalConstructor() { - // @ts-expect-error illegal constructor assertThrows(() => new Cache(), TypeError, "Illegal constructor"); // @ts-expect-error illegal constructor assertThrows(() => new Cache("foo", "bar"), TypeError, "Illegal constructor"); diff --git a/cli/tsc/dts/lib.deno.shared_globals.d.ts b/cli/tsc/dts/lib.deno.shared_globals.d.ts index d11e2933b8..49b6f7956b 100644 --- a/cli/tsc/dts/lib.deno.shared_globals.d.ts +++ b/cli/tsc/dts/lib.deno.shared_globals.d.ts @@ -410,7 +410,7 @@ declare function clearInterval(id?: number): void; declare function clearTimeout(id?: number): void; /** @category Scheduling */ -interface VoidFunction { +declare interface VoidFunction { (): void; } @@ -442,7 +442,7 @@ declare function queueMicrotask(func: VoidFunction): void; declare function dispatchEvent(event: Event): boolean; /** @category DOM APIs */ -interface DOMStringList { +declare interface DOMStringList { /** Returns the number of strings in strings. */ readonly length: number; /** Returns true if strings contains string, and false otherwise. */ @@ -453,13 +453,13 @@ interface DOMStringList { } /** @category Typed Arrays */ -type BufferSource = ArrayBufferView | ArrayBuffer; +declare type BufferSource = ArrayBufferView | ArrayBuffer; /** @category Console and Debugging */ declare var console: Console; /** @category DOM Events */ -interface ErrorEventInit extends EventInit { +declare interface ErrorEventInit extends EventInit { message?: string; filename?: string; lineno?: number; @@ -468,54 +468,63 @@ interface ErrorEventInit extends EventInit { } /** @category DOM Events */ -declare class ErrorEvent extends Event { +declare interface ErrorEvent extends Event { readonly message: string; readonly filename: string; readonly lineno: number; readonly colno: number; readonly error: any; - constructor(type: string, eventInitDict?: ErrorEventInit); } +/** @category DOM Events */ +declare var ErrorEvent: { + readonly prototype: ErrorEvent; + new (type: string, eventInitDict?: ErrorEventInit): ErrorEvent; +}; + /** @category Observability */ -interface PromiseRejectionEventInit extends EventInit { +declare interface PromiseRejectionEventInit extends EventInit { promise: Promise; reason?: any; } /** @category Observability */ -declare class PromiseRejectionEvent extends Event { +declare interface PromiseRejectionEvent extends Event { readonly promise: Promise; readonly reason: any; - constructor(type: string, eventInitDict?: PromiseRejectionEventInit); } +/** @category Observability */ +declare var PromiseRejectionEvent: { + readonly prototype: PromiseRejectionEvent; + new ( + type: string, + eventInitDict?: PromiseRejectionEventInit, + ): PromiseRejectionEvent; +}; + /** @category Web Workers */ -interface AbstractWorkerEventMap { +declare interface AbstractWorkerEventMap { "error": ErrorEvent; } /** @category Web Workers */ -interface WorkerEventMap extends AbstractWorkerEventMap { +declare interface WorkerEventMap extends AbstractWorkerEventMap { "message": MessageEvent; "messageerror": MessageEvent; } /** @category Web Workers */ -interface WorkerOptions { +declare interface WorkerOptions { type?: "classic" | "module"; name?: string; } /** @category Web Workers */ -declare class Worker extends EventTarget { +declare interface Worker extends EventTarget { onerror?: (e: ErrorEvent) => void; onmessage?: (e: MessageEvent) => void; onmessageerror?: (e: MessageEvent) => void; - constructor( - specifier: string | URL, - options?: WorkerOptions, - ); postMessage(message: any, transfer: Transferable[]): void; postMessage(message: any, options?: StructuredSerializeOptions): void; addEventListener( @@ -541,14 +550,19 @@ declare class Worker extends EventTarget { terminate(): void; } +/** @category Web Workers */ +declare var Worker: { + readonly prototype: Worker; + new (specifier: string | URL, options?: WorkerOptions): Worker; +}; + /** @category Performance */ declare type PerformanceEntryList = PerformanceEntry[]; /** @category Performance */ -declare class Performance extends EventTarget { +declare interface Performance extends EventTarget { /** Returns a timestamp representing the start of the performance measurement. */ readonly timeOrigin: number; - constructor(); /** Removes the stored timestamp with the associated name. */ clearMarks(markName?: string): void; @@ -594,6 +608,12 @@ declare class Performance extends EventTarget { toJSON(): any; } +/** @category Performance */ +declare var Performance: { + readonly prototype: Performance; + new (): never; +}; + /** @category Performance */ declare var performance: Performance; @@ -628,7 +648,7 @@ declare interface PerformanceMeasureOptions { * * @category Performance */ -declare class PerformanceEntry { +declare interface PerformanceEntry { readonly duration: number; readonly entryType: string; readonly name: string; @@ -636,6 +656,30 @@ declare class PerformanceEntry { toJSON(): any; } +/** Encapsulates a single performance metric that is part of the performance + * timeline. A performance entry can be directly created by making a performance + * mark or measure (for example by calling the `.mark()` method) at an explicit + * point in an application. + * + * @category Performance + */ +declare var PerformanceEntry: { + readonly prototype: PerformanceEntry; + new (): never; +}; + +/** `PerformanceMark` is an abstract interface for `PerformanceEntry` objects + * with an entryType of `"mark"`. Entries of this type are created by calling + * `performance.mark()` to add a named `DOMHighResTimeStamp` (the mark) to the + * performance timeline. + * + * @category Performance + */ +declare interface PerformanceMark extends PerformanceEntry { + readonly detail: any; + readonly entryType: "mark"; +} + /** `PerformanceMark` is an abstract interface for `PerformanceEntry` objects * with an entryType of `"mark"`. Entries of this type are created by calling * `performance.mark()` to add a named `DOMHighResTimeStamp` (the mark) to the @@ -643,10 +687,21 @@ declare class PerformanceEntry { * * @category Performance */ -declare class PerformanceMark extends PerformanceEntry { +declare var PerformanceMark: { + readonly prototype: PerformanceMark; + new (name: string, options?: PerformanceMarkOptions): PerformanceMark; +}; + +/** `PerformanceMeasure` is an abstract interface for `PerformanceEntry` objects + * with an entryType of `"measure"`. Entries of this type are created by calling + * `performance.measure()` to add a named `DOMHighResTimeStamp` (the measure) + * between two marks to the performance timeline. + * + * @category Performance + */ +declare interface PerformanceMeasure extends PerformanceEntry { readonly detail: any; - readonly entryType: "mark"; - constructor(name: string, options?: PerformanceMarkOptions); + readonly entryType: "measure"; } /** `PerformanceMeasure` is an abstract interface for `PerformanceEntry` objects @@ -656,10 +711,10 @@ declare class PerformanceMark extends PerformanceEntry { * * @category Performance */ -declare class PerformanceMeasure extends PerformanceEntry { - readonly detail: any; - readonly entryType: "measure"; -} +declare var PerformanceMeasure: { + readonly prototype: PerformanceMeasure; + new (): never; +}; /** @category DOM Events */ declare interface CustomEventInit extends EventInit { @@ -667,15 +722,20 @@ declare interface CustomEventInit extends EventInit { } /** @category DOM Events */ -declare class CustomEvent extends Event { - constructor(typeArg: string, eventInitDict?: CustomEventInit); +declare interface CustomEvent extends Event { /** Returns any custom data event was created with. Typically used for * synthetic events. */ readonly detail: T; } +/** @category DOM Events */ +declare var CustomEvent: { + readonly prototype: CustomEvent; + new (typeArg: string, eventInitDict?: CustomEventInit): CustomEvent; +}; + /** @category DOM APIs */ -interface ErrorConstructor { +declare interface ErrorConstructor { /** See https://v8.dev/docs/stack-trace-api#stack-trace-collection-for-custom-exceptions. */ captureStackTrace(error: Object, constructor?: Function): void; // TODO(nayeemrmn): Support `Error.prepareStackTrace()`. We currently use this diff --git a/cli/tsc/dts/lib.deno.unstable.d.ts b/cli/tsc/dts/lib.deno.unstable.d.ts index 8f11adfff9..bc770dab8f 100644 --- a/cli/tsc/dts/lib.deno.unstable.d.ts +++ b/cli/tsc/dts/lib.deno.unstable.d.ts @@ -2268,10 +2268,19 @@ declare interface WebSocketCloseInfo { * @tags allow-net * @category Web Sockets */ -declare class WebSocketStream { - constructor(url: string, options?: WebSocketStreamOptions); +declare interface WebSocketStream { url: string; connection: Promise; closed: Promise; close(closeInfo?: WebSocketCloseInfo): void; } + +/** **UNSTABLE**: New API, yet to be vetted. + * + * @tags allow-net + * @category Web Sockets + */ +declare var WebSocketStream: { + readonly prototype: WebSocketStream; + new (url: string, options?: WebSocketStreamOptions): WebSocketStream; +}; diff --git a/cli/tsc/dts/lib.deno.window.d.ts b/cli/tsc/dts/lib.deno.window.d.ts index d0cd9b5bd3..2edb2ce8fb 100644 --- a/cli/tsc/dts/lib.deno.window.d.ts +++ b/cli/tsc/dts/lib.deno.window.d.ts @@ -8,14 +8,13 @@ /// /** @category Web APIs */ -interface WindowEventMap { +declare interface WindowEventMap { "error": ErrorEvent; "unhandledrejection": PromiseRejectionEvent; } /** @category Web APIs */ -declare class Window extends EventTarget { - new(): Window; +declare interface Window extends EventTarget { readonly window: Window & typeof globalThis; readonly self: Window & typeof globalThis; onerror: ((this: Window, ev: ErrorEvent) => any) | null; @@ -67,10 +66,20 @@ declare class Window extends EventTarget { ): void; } +/** @category Web APIs */ +declare var Window: { + readonly prototype: Window; + new (): never; +}; + /** @category Web APIs */ declare var window: Window & typeof globalThis; /** @category Web APIs */ declare var self: Window & typeof globalThis; +/** @category Web APIs */ +declare var closed: boolean; +/** @category Web APIs */ +declare function close(): void; /** @category DOM Events */ declare var onerror: ((this: Window, ev: ErrorEvent) => any) | null; /** @category DOM Events */ @@ -91,14 +100,19 @@ declare var sessionStorage: Storage; declare var caches: CacheStorage; /** @category Web APIs */ -declare class Navigator { - constructor(); +declare interface Navigator { readonly hardwareConcurrency: number; readonly userAgent: string; readonly language: string; readonly languages: string[]; } +/** @category Web APIs */ +declare var Navigator: { + readonly prototype: Navigator; + new (): never; +}; + /** @category Web APIs */ declare var navigator: Navigator; @@ -199,8 +213,7 @@ declare function removeEventListener( * * @category Web APIs */ -declare class Location { - constructor(); +declare interface Location { /** Returns a DOMStringList object listing the origins of the ancestor * browsing contexts, from the parent browsing context to the top-level * browsing context. @@ -262,6 +275,19 @@ declare class Location { replace(url: string): void; } +// TODO(nayeemrmn): Move this to `extensions/web` where its implementation is. +// The types there must first be split into window, worker and global types. +/** The location (URL) of the object it is linked to. Changes done on it are + * reflected on the object it relates to. Accessible via + * `globalThis.location`. + * + * @category Web APIs + */ +declare var Location: { + readonly prototype: Location; + new (): never; +}; + // TODO(nayeemrmn): Move this to `extensions/web` where its implementation is. // The types there must first be split into window, worker and global types. /** @category Web APIs */ diff --git a/cli/tsc/dts/lib.deno.worker.d.ts b/cli/tsc/dts/lib.deno.worker.d.ts index 752a427c93..b165f2086b 100644 --- a/cli/tsc/dts/lib.deno.worker.d.ts +++ b/cli/tsc/dts/lib.deno.worker.d.ts @@ -7,13 +7,13 @@ /// /** @category Web Workers */ -interface WorkerGlobalScopeEventMap { +declare interface WorkerGlobalScopeEventMap { "error": ErrorEvent; "unhandledrejection": PromiseRejectionEvent; } /** @category Web Workers */ -declare class WorkerGlobalScope extends EventTarget { +declare interface WorkerGlobalScope extends EventTarget { readonly location: WorkerLocation; readonly navigator: WorkerNavigator; onerror: ((this: WorkerGlobalScope, ev: ErrorEvent) => any) | null; @@ -54,26 +54,38 @@ declare class WorkerGlobalScope extends EventTarget { caches: CacheStorage; } +/** @category Web Workers */ +declare var WorkerGlobalScope: { + readonly prototype: WorkerGlobalScope; + new (): never; +}; + /** @category Web APIs */ -declare class WorkerNavigator { - constructor(); +declare interface WorkerNavigator { readonly hardwareConcurrency: number; readonly userAgent: string; readonly language: string; readonly languages: string[]; } +/** @category Web APIs */ +declare var WorkerNavigator: { + readonly prototype: WorkerNavigator; + new (): never; +}; + /** @category Web APIs */ declare var navigator: WorkerNavigator; /** @category Web Workers */ -interface DedicatedWorkerGlobalScopeEventMap extends WorkerGlobalScopeEventMap { +declare interface DedicatedWorkerGlobalScopeEventMap + extends WorkerGlobalScopeEventMap { "message": MessageEvent; "messageerror": MessageEvent; } /** @category Web APIs */ -declare class DedicatedWorkerGlobalScope extends WorkerGlobalScope { +declare interface DedicatedWorkerGlobalScope extends WorkerGlobalScope { readonly name: string; onmessage: | ((this: DedicatedWorkerGlobalScope, ev: MessageEvent) => any) @@ -112,6 +124,12 @@ declare class DedicatedWorkerGlobalScope extends WorkerGlobalScope { ): void; } +/** @category Web APIs */ +declare var DedicatedWorkerGlobalScope: { + readonly prototype: DedicatedWorkerGlobalScope; + new (): never; +}; + /** @category Web Workers */ declare var name: string; /** @category Web Workers */ @@ -186,8 +204,7 @@ declare function removeEventListener( * * @category Web APIs */ -declare class WorkerLocation { - constructor(); +declare interface WorkerLocation { readonly hash: string; readonly host: string; readonly hostname: string; @@ -200,6 +217,19 @@ declare class WorkerLocation { readonly search: string; } +// TODO(nayeemrmn): Move this to `extensions/web` where its implementation is. +// The types there must first be split into window, worker and global types. +/** The absolute location of the script executed by the Worker. Such an object + * is initialized for each worker and is available via the + * WorkerGlobalScope.location property obtained by calling self.location. + * + * @category Web APIs + */ +declare var WorkerLocation: { + readonly prototype: WorkerLocation; + new (): never; +}; + // TODO(nayeemrmn): Move this to `extensions/web` where its implementation is. // The types there must first be split into window, worker and global types. /** @category Web APIs */ diff --git a/cli/tsc/dts/lib.dom.extras.d.ts b/cli/tsc/dts/lib.dom.extras.d.ts index 9116596a6a..441eb9221d 100644 --- a/cli/tsc/dts/lib.dom.extras.d.ts +++ b/cli/tsc/dts/lib.dom.extras.d.ts @@ -59,7 +59,7 @@ declare interface URLPatternResult { * ```ts * // Specify the pattern as structured data. * const pattern = new URLPattern({ pathname: "/users/:user" }); - * const match = pattern.exec("/users/joe"); + * const match = pattern.exec("https://blog.example.com/users/joe"); * console.log(match.pathname.groups.user); // joe * ``` * @@ -72,24 +72,23 @@ declare interface URLPatternResult { * * ```ts * // Specify a relative string pattern with a base URL. - * const pattern = new URLPattern("/:article", "https://blog.example.com"); - * console.log(pattern.test("https://blog.example.com/article")); // true - * console.log(pattern.test("https://blog.example.com/article/123")); // false + * const pattern = new URLPattern("/article/:id", "https://blog.example.com"); + * console.log(pattern.test("https://blog.example.com/article")); // false + * console.log(pattern.test("https://blog.example.com/article/123")); // true * ``` */ -declare class URLPattern { - constructor(input: URLPatternInput, baseURL?: string); - +interface URLPattern { /** * Test if the given input matches the stored pattern. * - * The input can either be provided as a url string (with an optional base), - * or as individual components in the form of an object. + * The input can either be provided as an absolute URL string with an optional base, + * relative URL string with a required base, or as individual components + * in the form of an `URLPatternInit` object. * * ```ts * const pattern = new URLPattern("https://example.com/books/:id"); * - * // Test a url string. + * // Test an absolute url string. * console.log(pattern.test("https://example.com/books/123")); // true * * // Test a relative url with a base. @@ -104,13 +103,14 @@ declare class URLPattern { /** * Match the given input against the stored pattern. * - * The input can either be provided as a url string (with an optional base), - * or as individual components in the form of an object. + * The input can either be provided as an absolute URL string with an optional base, + * relative URL string with a required base, or as individual components + * in the form of an `URLPatternInit` object. * * ```ts * const pattern = new URLPattern("https://example.com/books/:id"); * - * // Match a url string. + * // Match an absolute url string. * let match = pattern.exec("https://example.com/books/123"); * console.log(match.pathname.groups.id); // 123 * @@ -143,6 +143,39 @@ declare class URLPattern { readonly hash: string; } +/** + * The URLPattern API provides a web platform primitive for matching URLs based + * on a convenient pattern syntax. + * + * The syntax is based on path-to-regexp. Wildcards, named capture groups, + * regular groups, and group modifiers are all supported. + * + * ```ts + * // Specify the pattern as structured data. + * const pattern = new URLPattern({ pathname: "/users/:user" }); + * const match = pattern.exec("https://blog.example.com/users/joe"); + * console.log(match.pathname.groups.user); // joe + * ``` + * + * ```ts + * // Specify a fully qualified string pattern. + * const pattern = new URLPattern("https://example.com/books/:id"); + * console.log(pattern.test("https://example.com/books/123")); // true + * console.log(pattern.test("https://deno.land/books/123")); // false + * ``` + * + * ```ts + * // Specify a relative string pattern with a base URL. + * const pattern = new URLPattern("/article/:id", "https://blog.example.com"); + * console.log(pattern.test("https://blog.example.com/article")); // false + * console.log(pattern.test("https://blog.example.com/article/123")); // true + * ``` + */ +declare var URLPattern: { + readonly prototype: URLPattern; + new (input: URLPatternInput, baseURL?: string): URLPattern; +}; + interface ErrorConstructor { /** See https://v8.dev/docs/stack-trace-api#stack-trace-collection-for-custom-exceptions. */ captureStackTrace(error: Object, constructor?: Function): void; diff --git a/ext/broadcast_channel/lib.deno_broadcast_channel.d.ts b/ext/broadcast_channel/lib.deno_broadcast_channel.d.ts index ea01bef360..1ffd6532dc 100644 --- a/ext/broadcast_channel/lib.deno_broadcast_channel.d.ts +++ b/ext/broadcast_channel/lib.deno_broadcast_channel.d.ts @@ -6,13 +6,13 @@ /// /** @category Broadcast Channel */ -interface BroadcastChannelEventMap { +declare interface BroadcastChannelEventMap { "message": MessageEvent; "messageerror": MessageEvent; } /** @category Broadcast Channel */ -interface BroadcastChannel extends EventTarget { +declare interface BroadcastChannel extends EventTarget { /** * Returns the channel name (as passed to the constructor). */ @@ -53,6 +53,6 @@ interface BroadcastChannel extends EventTarget { /** @category Broadcast Channel */ declare var BroadcastChannel: { - prototype: BroadcastChannel; + readonly prototype: BroadcastChannel; new (name: string): BroadcastChannel; }; diff --git a/ext/cache/lib.deno_cache.d.ts b/ext/cache/lib.deno_cache.d.ts index 0834d7f200..ca0218bf56 100644 --- a/ext/cache/lib.deno_cache.d.ts +++ b/ext/cache/lib.deno_cache.d.ts @@ -54,18 +54,18 @@ declare interface Cache { /** @category Cache API */ declare var Cache: { - prototype: Cache; - new (name: string): Cache; + readonly prototype: Cache; + new (): never; }; /** @category Cache API */ declare var CacheStorage: { - prototype: CacheStorage; - new (): CacheStorage; + readonly prototype: CacheStorage; + new (): never; }; /** @category Cache API */ -interface CacheQueryOptions { +declare interface CacheQueryOptions { ignoreMethod?: boolean; ignoreSearch?: boolean; ignoreVary?: boolean; diff --git a/ext/crypto/lib.deno_crypto.d.ts b/ext/crypto/lib.deno_crypto.d.ts index 6ff7b72b0f..2ad0c67f02 100644 --- a/ext/crypto/lib.deno_crypto.d.ts +++ b/ext/crypto/lib.deno_crypto.d.ts @@ -9,23 +9,23 @@ declare var crypto: Crypto; /** @category Web Crypto API */ -interface Algorithm { +declare interface Algorithm { name: string; } /** @category Web Crypto API */ -interface KeyAlgorithm { +declare interface KeyAlgorithm { name: string; } /** @category Web Crypto API */ -type AlgorithmIdentifier = string | Algorithm; +declare type AlgorithmIdentifier = string | Algorithm; /** @category Web Crypto API */ -type HashAlgorithmIdentifier = AlgorithmIdentifier; +declare type HashAlgorithmIdentifier = AlgorithmIdentifier; /** @category Web Crypto API */ -type KeyType = "private" | "public" | "secret"; +declare type KeyType = "private" | "public" | "secret"; /** @category Web Crypto API */ -type KeyUsage = +declare type KeyUsage = | "decrypt" | "deriveBits" | "deriveKey" @@ -35,19 +35,19 @@ type KeyUsage = | "verify" | "wrapKey"; /** @category Web Crypto API */ -type KeyFormat = "jwk" | "pkcs8" | "raw" | "spki"; +declare type KeyFormat = "jwk" | "pkcs8" | "raw" | "spki"; /** @category Web Crypto API */ -type NamedCurve = string; +declare type NamedCurve = string; /** @category Web Crypto API */ -interface RsaOtherPrimesInfo { +declare interface RsaOtherPrimesInfo { d?: string; r?: string; t?: string; } /** @category Web Crypto API */ -interface JsonWebKey { +declare interface JsonWebKey { alg?: string; crv?: string; d?: string; @@ -56,7 +56,6 @@ interface JsonWebKey { e?: string; ext?: boolean; k?: string; - // deno-lint-ignore camelcase key_ops?: string[]; kty?: string; n?: string; @@ -70,129 +69,129 @@ interface JsonWebKey { } /** @category Web Crypto API */ -interface AesCbcParams extends Algorithm { +declare interface AesCbcParams extends Algorithm { iv: BufferSource; } /** @category Web Crypto API */ -interface AesGcmParams extends Algorithm { +declare interface AesGcmParams extends Algorithm { iv: BufferSource; additionalData?: BufferSource; tagLength?: number; } /** @category Web Crypto API */ -interface AesCtrParams extends Algorithm { +declare interface AesCtrParams extends Algorithm { counter: BufferSource; length: number; } /** @category Web Crypto API */ -interface HmacKeyGenParams extends Algorithm { +declare interface HmacKeyGenParams extends Algorithm { hash: HashAlgorithmIdentifier; length?: number; } /** @category Web Crypto API */ -interface EcKeyGenParams extends Algorithm { +declare interface EcKeyGenParams extends Algorithm { namedCurve: NamedCurve; } /** @category Web Crypto API */ -interface EcKeyImportParams extends Algorithm { +declare interface EcKeyImportParams extends Algorithm { namedCurve: NamedCurve; } /** @category Web Crypto API */ -interface EcdsaParams extends Algorithm { +declare interface EcdsaParams extends Algorithm { hash: HashAlgorithmIdentifier; } /** @category Web Crypto API */ -interface RsaHashedImportParams extends Algorithm { +declare interface RsaHashedImportParams extends Algorithm { hash: HashAlgorithmIdentifier; } /** @category Web Crypto API */ -interface RsaHashedKeyGenParams extends RsaKeyGenParams { +declare interface RsaHashedKeyGenParams extends RsaKeyGenParams { hash: HashAlgorithmIdentifier; } /** @category Web Crypto API */ -interface RsaKeyGenParams extends Algorithm { +declare interface RsaKeyGenParams extends Algorithm { modulusLength: number; publicExponent: Uint8Array; } /** @category Web Crypto API */ -interface RsaPssParams extends Algorithm { +declare interface RsaPssParams extends Algorithm { saltLength: number; } /** @category Web Crypto API */ -interface RsaOaepParams extends Algorithm { +declare interface RsaOaepParams extends Algorithm { label?: Uint8Array; } /** @category Web Crypto API */ -interface HmacImportParams extends Algorithm { +declare interface HmacImportParams extends Algorithm { hash: HashAlgorithmIdentifier; length?: number; } /** @category Web Crypto API */ -interface EcKeyAlgorithm extends KeyAlgorithm { +declare interface EcKeyAlgorithm extends KeyAlgorithm { namedCurve: NamedCurve; } /** @category Web Crypto API */ -interface HmacKeyAlgorithm extends KeyAlgorithm { +declare interface HmacKeyAlgorithm extends KeyAlgorithm { hash: KeyAlgorithm; length: number; } /** @category Web Crypto API */ -interface RsaHashedKeyAlgorithm extends RsaKeyAlgorithm { +declare interface RsaHashedKeyAlgorithm extends RsaKeyAlgorithm { hash: KeyAlgorithm; } /** @category Web Crypto API */ -interface RsaKeyAlgorithm extends KeyAlgorithm { +declare interface RsaKeyAlgorithm extends KeyAlgorithm { modulusLength: number; publicExponent: Uint8Array; } /** @category Web Crypto API */ -interface HkdfParams extends Algorithm { +declare interface HkdfParams extends Algorithm { hash: HashAlgorithmIdentifier; info: BufferSource; salt: BufferSource; } /** @category Web Crypto API */ -interface Pbkdf2Params extends Algorithm { +declare interface Pbkdf2Params extends Algorithm { hash: HashAlgorithmIdentifier; iterations: number; salt: BufferSource; } /** @category Web Crypto API */ -interface AesDerivedKeyParams extends Algorithm { +declare interface AesDerivedKeyParams extends Algorithm { length: number; } /** @category Web Crypto API */ -interface EcdhKeyDeriveParams extends Algorithm { +declare interface EcdhKeyDeriveParams extends Algorithm { public: CryptoKey; } /** @category Web Crypto API */ -interface AesKeyGenParams extends Algorithm { +declare interface AesKeyGenParams extends Algorithm { length: number; } /** @category Web Crypto API */ -interface AesKeyAlgorithm extends KeyAlgorithm { +declare interface AesKeyAlgorithm extends KeyAlgorithm { length: number; } @@ -201,7 +200,7 @@ interface AesKeyAlgorithm extends KeyAlgorithm { * * @category Web Crypto API */ -interface CryptoKey { +declare interface CryptoKey { readonly algorithm: KeyAlgorithm; readonly extractable: boolean; readonly type: KeyType; @@ -210,8 +209,8 @@ interface CryptoKey { /** @category Web Crypto API */ declare var CryptoKey: { - prototype: CryptoKey; - new (): CryptoKey; + readonly prototype: CryptoKey; + new (): never; }; /** The CryptoKeyPair dictionary of the Web Crypto API represents a key pair for @@ -219,15 +218,15 @@ declare var CryptoKey: { * * @category Web Crypto API */ -interface CryptoKeyPair { +declare interface CryptoKeyPair { privateKey: CryptoKey; publicKey: CryptoKey; } /** @category Web Crypto API */ declare var CryptoKeyPair: { - prototype: CryptoKeyPair; - new (): CryptoKeyPair; + readonly prototype: CryptoKeyPair; + new (): never; }; /** This Web Crypto API interface provides a number of low-level cryptographic @@ -236,7 +235,7 @@ declare var CryptoKeyPair: { * * @category Web Crypto API */ -interface SubtleCrypto { +declare interface SubtleCrypto { generateKey( algorithm: RsaHashedKeyGenParams | EcKeyGenParams, extractable: boolean, @@ -368,6 +367,12 @@ interface SubtleCrypto { ): Promise; } +/** @category Web Crypto API */ +declare var SubtleCrypto: { + readonly prototype: SubtleCrypto; + new (): never; +}; + /** @category Web Crypto API */ declare interface Crypto { readonly subtle: SubtleCrypto; @@ -389,7 +394,7 @@ declare interface Crypto { } /** @category Web Crypto API */ -declare var SubtleCrypto: { - prototype: SubtleCrypto; - new (): SubtleCrypto; +declare var Crypto: { + readonly prototype: Crypto; + new (): never; }; diff --git a/ext/fetch/lib.deno_fetch.d.ts b/ext/fetch/lib.deno_fetch.d.ts index 5031cc4315..7f574b76ed 100644 --- a/ext/fetch/lib.deno_fetch.d.ts +++ b/ext/fetch/lib.deno_fetch.d.ts @@ -6,7 +6,7 @@ /// /** @category DOM APIs */ -interface DomIterable { +declare interface DomIterable { keys(): IterableIterator; values(): IterableIterator; entries(): IterableIterator<[K, V]>; @@ -18,7 +18,7 @@ interface DomIterable { } /** @category Fetch API */ -type FormDataEntryValue = File | string; +declare type FormDataEntryValue = File | string; /** Provides a way to easily construct a set of key/value pairs representing * form fields and their values, which can then be easily sent using the @@ -27,31 +27,23 @@ type FormDataEntryValue = File | string; * * @category Fetch API */ -interface FormData { +declare interface FormData extends DomIterable { append(name: string, value: string | Blob, fileName?: string): void; delete(name: string): void; get(name: string): FormDataEntryValue | null; getAll(name: string): FormDataEntryValue[]; has(name: string): boolean; set(name: string, value: string | Blob, fileName?: string): void; - keys(): IterableIterator; - values(): IterableIterator; - entries(): IterableIterator<[string, FormDataEntryValue]>; - [Symbol.iterator](): IterableIterator<[string, FormDataEntryValue]>; - forEach( - callback: (value: FormDataEntryValue, key: string, parent: this) => void, - thisArg?: any, - ): void; } /** @category Fetch API */ declare var FormData: { - prototype: FormData; + readonly prototype: FormData; new (): FormData; }; /** @category Fetch API */ -interface Body { +declare interface Body { /** A simple getter used to expose a `ReadableStream` of the body contents. */ readonly body: ReadableStream | null; /** Stores a `Boolean` that declares whether the body has been used in a @@ -81,7 +73,7 @@ interface Body { } /** @category Fetch API */ -type HeadersInit = Headers | string[][] | Record; +declare type HeadersInit = Iterable | Record; /** This Fetch API interface allows you to perform various actions on HTTP * request and response headers. These actions include retrieving, setting, @@ -93,33 +85,13 @@ type HeadersInit = Headers | string[][] | Record; * * @category Fetch API */ -interface Headers { - append(name: string, value: string): void; - delete(name: string): void; - get(name: string): string | null; - has(name: string): boolean; - set(name: string, value: string): void; - forEach( - callbackfn: (value: string, key: string, parent: Headers) => void, - thisArg?: any, - ): void; -} - -/** @category Fetch API */ -declare class Headers implements DomIterable { - constructor(init?: HeadersInit); - +declare interface Headers extends DomIterable { /** Appends a new value onto an existing header inside a `Headers` object, or * adds the header if it does not already exist. */ append(name: string, value: string): void; /** Deletes a header from a `Headers` object. */ delete(name: string): void; - /** Returns an iterator allowing to go through all key/value pairs - * contained in this Headers object. The both the key and value of each pairs - * are ByteString objects. - */ - entries(): IterableIterator<[string, string]>; /** Returns a `ByteString` sequence of all the values of a header within a * `Headers` object with a given name. */ @@ -128,32 +100,35 @@ declare class Headers implements DomIterable { * header. */ has(name: string): boolean; - /** Returns an iterator allowing to go through all keys contained in - * this Headers object. The keys are ByteString objects. - */ - keys(): IterableIterator; /** Sets a new value for an existing header inside a Headers object, or adds * the header if it does not already exist. */ set(name: string, value: string): void; - /** Returns an iterator allowing to go through all values contained in - * this Headers object. The values are ByteString objects. + /** Returns an array containing the values of all `Set-Cookie` headers + * associated with a response. */ - values(): IterableIterator; - forEach( - callbackfn: (value: string, key: string, parent: this) => void, - thisArg?: any, - ): void; - /** The Symbol.iterator well-known symbol specifies the default - * iterator for this Headers object - */ - [Symbol.iterator](): IterableIterator<[string, string]>; + getSetCookie(): string[]; } +/** This Fetch API interface allows you to perform various actions on HTTP + * request and response headers. These actions include retrieving, setting, + * adding to, and removing. A Headers object has an associated header list, + * which is initially empty and consists of zero or more name and value pairs. + * You can add to this using methods like append() (see Examples). In all + * methods of this interface, header names are matched by case-insensitive byte + * sequence. + * + * @category Fetch API + */ +declare var Headers: { + readonly prototype: Headers; + new (init?: HeadersInit): Headers; +}; + /** @category Fetch API */ -type RequestInfo = Request | string; +declare type RequestInfo = Request | string; /** @category Fetch API */ -type RequestCache = +declare type RequestCache = | "default" | "force-cache" | "no-cache" @@ -161,13 +136,13 @@ type RequestCache = | "only-if-cached" | "reload"; /** @category Fetch API */ -type RequestCredentials = "include" | "omit" | "same-origin"; +declare type RequestCredentials = "include" | "omit" | "same-origin"; /** @category Fetch API */ -type RequestMode = "cors" | "navigate" | "no-cors" | "same-origin"; +declare type RequestMode = "cors" | "navigate" | "no-cors" | "same-origin"; /** @category Fetch API */ -type RequestRedirect = "error" | "follow" | "manual"; +declare type RequestRedirect = "error" | "follow" | "manual"; /** @category Fetch API */ -type ReferrerPolicy = +declare type ReferrerPolicy = | "" | "no-referrer" | "no-referrer-when-downgrade" @@ -178,7 +153,7 @@ type ReferrerPolicy = | "strict-origin-when-cross-origin" | "unsafe-url"; /** @category Fetch API */ -type BodyInit = +declare type BodyInit = | Blob | BufferSource | FormData @@ -186,7 +161,7 @@ type BodyInit = | ReadableStream | string; /** @category Fetch API */ -type RequestDestination = +declare type RequestDestination = | "" | "audio" | "audioworklet" @@ -207,7 +182,7 @@ type RequestDestination = | "xslt"; /** @category Fetch API */ -interface RequestInit { +declare interface RequestInit { /** * A BodyInit object or null to set request's body. */ @@ -275,9 +250,7 @@ interface RequestInit { * * @category Fetch API */ -declare class Request implements Body { - constructor(input: RequestInfo | URL, init?: RequestInit); - +declare interface Request extends Body { /** * Returns the cache mode associated with request, which is a string * indicating how the request will interact with the browser's cache when @@ -361,44 +334,26 @@ declare class Request implements Body { */ readonly url: string; clone(): Request; - - /** A simple getter used to expose a `ReadableStream` of the body contents. */ - readonly body: ReadableStream | null; - /** Stores a `Boolean` that declares whether the body has been used in a - * request yet. - */ - readonly bodyUsed: boolean; - /** Takes a `Request` stream and reads it to completion. It returns a promise - * that resolves with an `ArrayBuffer`. - */ - arrayBuffer(): Promise; - /** Takes a `Request` stream and reads it to completion. It returns a promise - * that resolves with a `Blob`. - */ - blob(): Promise; - /** Takes a `Request` stream and reads it to completion. It returns a promise - * that resolves with a `FormData` object. - */ - formData(): Promise; - /** Takes a `Request` stream and reads it to completion. It returns a promise - * that resolves with the result of parsing the body text as JSON. - */ - json(): Promise; - /** Takes a `Request` stream and reads it to completion. It returns a promise - * that resolves with a `USVString` (text). - */ - text(): Promise; } +/** This Fetch API interface represents a resource request. + * + * @category Fetch API + */ +declare var Request: { + readonly prototype: Request; + new (input: RequestInfo | URL, init?: RequestInit): Request; +}; + /** @category Fetch API */ -interface ResponseInit { +declare interface ResponseInit { headers?: HeadersInit; status?: number; statusText?: string; } /** @category Fetch API */ -type ResponseType = +declare type ResponseType = | "basic" | "cors" | "default" @@ -410,12 +365,7 @@ type ResponseType = * * @category Fetch API */ -declare class Response implements Body { - constructor(body?: BodyInit | null, init?: ResponseInit); - static json(data: unknown, init?: ResponseInit): Response; - static error(): Response; - static redirect(url: string | URL, status?: number): Response; - +declare interface Response extends Body { readonly headers: Headers; readonly ok: boolean; readonly redirected: boolean; @@ -424,35 +374,20 @@ declare class Response implements Body { readonly type: ResponseType; readonly url: string; clone(): Response; - - /** A simple getter used to expose a `ReadableStream` of the body contents. */ - readonly body: ReadableStream | null; - /** Stores a `Boolean` that declares whether the body has been used in a - * response yet. - */ - readonly bodyUsed: boolean; - /** Takes a `Response` stream and reads it to completion. It returns a promise - * that resolves with an `ArrayBuffer`. - */ - arrayBuffer(): Promise; - /** Takes a `Response` stream and reads it to completion. It returns a promise - * that resolves with a `Blob`. - */ - blob(): Promise; - /** Takes a `Response` stream and reads it to completion. It returns a promise - * that resolves with a `FormData` object. - */ - formData(): Promise; - /** Takes a `Response` stream and reads it to completion. It returns a promise - * that resolves with the result of parsing the body text as JSON. - */ - json(): Promise; - /** Takes a `Response` stream and reads it to completion. It returns a promise - * that resolves with a `USVString` (text). - */ - text(): Promise; } +/** This Fetch API interface represents the response to a request. + * + * @category Fetch API + */ +declare var Response: { + readonly prototype: Response; + new (body?: BodyInit | null, init?: ResponseInit): Response; + json(data: unknown, init?: ResponseInit): Response; + error(): Response; + redirect(url: string | URL, status?: number): Response; +}; + /** Fetch a resource from the network. It returns a `Promise` that resolves to the * `Response` to that `Request`, whether it is successful or not. * diff --git a/ext/url/lib.deno_url.d.ts b/ext/url/lib.deno_url.d.ts index 9a8c155d99..6da1c57040 100644 --- a/ext/url/lib.deno_url.d.ts +++ b/ext/url/lib.deno_url.d.ts @@ -1,17 +1,12 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -// deno-lint-ignore-file no-explicit-any +// deno-lint-ignore-file no-explicit-any no-var /// /// /** @category Web APIs */ -declare class URLSearchParams { - constructor( - init?: string[][] | Record | string | URLSearchParams, - ); - static toString(): string; - +declare interface URLSearchParams { /** Appends a specified key/value pair as a new search parameter. * * ```ts @@ -22,15 +17,16 @@ declare class URLSearchParams { */ append(name: string, value: string): void; - /** Deletes the given search parameter and its associated value, + /** Deletes search parameters that match a name, and optional value, * from the list of all search parameters. * * ```ts * let searchParams = new URLSearchParams([['name', 'value']]); * searchParams.delete('name'); + * searchParams.delete('name', 'value'); * ``` */ - delete(name: string): void; + delete(name: string, value?: string): void; /** Returns all the values associated with a given search parameter * as an array. @@ -49,14 +45,15 @@ declare class URLSearchParams { */ get(name: string): string | null; - /** Returns a Boolean that indicates whether a parameter with the - * specified name exists. + /** Returns a boolean value indicating if a given parameter, + * or parameter and value pair, exists. * * ```ts * searchParams.has('name'); + * searchParams.has('name', 'value'); * ``` */ - has(name: string): boolean; + has(name: string, value?: string): boolean; /** Sets the value associated with a given search parameter to the * given value. If there were several matching values, this method @@ -160,17 +157,20 @@ declare class URLSearchParams { size: number; } +/** @category Web APIs */ +declare var URLSearchParams: { + readonly prototype: URLSearchParams; + new ( + init?: Iterable | Record | string, + ): URLSearchParams; +}; + /** The URL interface represents an object providing static methods used for * creating object URLs. * * @category Web APIs */ -declare class URL { - constructor(url: string | URL, base?: string | URL); - static canParse(url: string | URL, base?: string | URL): boolean; - static createObjectURL(blob: Blob): string; - static revokeObjectURL(url: string): void; - +declare interface URL { hash: string; host: string; hostname: string; @@ -187,6 +187,19 @@ declare class URL { toJSON(): string; } +/** The URL interface represents an object providing static methods used for + * creating object URLs. + * + * @category Web APIs + */ +declare var URL: { + readonly prototype: URL; + new (url: string | URL, base?: string | URL): URL; + canParse(url: string | URL, base?: string | URL): boolean; + createObjectURL(blob: Blob): string; + revokeObjectURL(url: string): void; +}; + /** @category Web APIs */ declare interface URLPatternInit { protocol?: string; @@ -265,9 +278,7 @@ declare interface URLPatternResult { * * @category Web APIs */ -declare class URLPattern { - constructor(input: URLPatternInput, baseURL?: string); - +declare interface URLPattern { /** * Test if the given input matches the stored pattern. * @@ -332,3 +343,38 @@ declare class URLPattern { /** The pattern string for the `hash`. */ readonly hash: string; } + +/** + * The URLPattern API provides a web platform primitive for matching URLs based + * on a convenient pattern syntax. + * + * The syntax is based on path-to-regexp. Wildcards, named capture groups, + * regular groups, and group modifiers are all supported. + * + * ```ts + * // Specify the pattern as structured data. + * const pattern = new URLPattern({ pathname: "/users/:user" }); + * const match = pattern.exec("https://blog.example.com/users/joe"); + * console.log(match.pathname.groups.user); // joe + * ``` + * + * ```ts + * // Specify a fully qualified string pattern. + * const pattern = new URLPattern("https://example.com/books/:id"); + * console.log(pattern.test("https://example.com/books/123")); // true + * console.log(pattern.test("https://deno.land/books/123")); // false + * ``` + * + * ```ts + * // Specify a relative string pattern with a base URL. + * const pattern = new URLPattern("/article/:id", "https://blog.example.com"); + * console.log(pattern.test("https://blog.example.com/article")); // false + * console.log(pattern.test("https://blog.example.com/article/123")); // true + * ``` + * + * @category Web APIs + */ +declare var URLPattern: { + readonly prototype: URLPattern; + new (input: URLPatternInput, baseURL?: string): URLPattern; +}; diff --git a/ext/web/lib.deno_web.d.ts b/ext/web/lib.deno_web.d.ts index e1ffdc3296..331c9536b1 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 + * ,