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. --- cli/tsc/dts/lib.deno.window.d.ts | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) (limited to 'cli/tsc/dts/lib.deno.window.d.ts') diff --git a/cli/tsc/dts/lib.deno.window.d.ts b/cli/tsc/dts/lib.deno.window.d.ts index d0cd9b5bd..2edb2ce8f 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 */ -- cgit v1.2.3