Remove __domTypes namespace (#4698)

This commit is contained in:
Ryan Dahl 2020-04-10 14:24:42 -04:00 committed by GitHub
parent 8b4508338b
commit 2af9f5f2cf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 170 additions and 212 deletions

View file

@ -9,16 +9,8 @@
/// <reference lib="deno.ns" /> /// <reference lib="deno.ns" />
/// <reference lib="esnext" /> /// <reference lib="esnext" />
// https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope
declare interface WindowOrWorkerGlobalScope {
ReadableStream: __domTypes.ReadableStreamConstructor;
location: __domTypes.Location;
}
// This follows the WebIDL at: https://webassembly.github.io/spec/js-api/ // This follows the WebIDL at: https://webassembly.github.io/spec/js-api/
// and: https://webassembly.github.io/spec/web-api/ // and: https://webassembly.github.io/spec/web-api/
declare namespace WebAssembly { declare namespace WebAssembly {
interface WebAssemblyInstantiatedSource { interface WebAssemblyInstantiatedSource {
module: Module; module: Module;
@ -203,8 +195,7 @@ declare function clearInterval(id?: number): void;
declare function queueMicrotask(func: Function): void; declare function queueMicrotask(func: Function): void;
declare const console: Console; declare const console: Console;
declare const location: __domTypes.Location; declare const location: Location;
declare const ReadableStream: __domTypes.ReadableStreamConstructor;
declare function addEventListener( declare function addEventListener(
type: string, type: string,
@ -220,15 +211,12 @@ declare function removeEventListener(
options?: boolean | EventListenerOptions | undefined options?: boolean | EventListenerOptions | undefined
): void; ): void;
declare type ReadableStream<R = any> = __domTypes.ReadableStream<R>;
declare interface ImportMeta { declare interface ImportMeta {
url: string; url: string;
main: boolean; main: boolean;
} }
declare namespace __domTypes { interface DomIterable<K, V> {
export interface DomIterable<K, V> {
keys(): IterableIterator<K>; keys(): IterableIterator<K>;
values(): IterableIterator<V>; values(): IterableIterator<V>;
entries(): IterableIterator<[K, V]>; entries(): IterableIterator<[K, V]>;
@ -237,93 +225,77 @@ declare namespace __domTypes {
callback: (value: V, key: K, parent: this) => void, callback: (value: V, key: K, parent: this) => void,
thisArg?: any thisArg?: any
): void; ): void;
} }
export interface ReadableStreamReadDoneResult<T> {
interface ReadableStreamReadDoneResult<T> {
done: true; done: true;
value?: T; value?: T;
} }
export interface ReadableStreamReadValueResult<T> {
interface ReadableStreamReadValueResult<T> {
done: false; done: false;
value: T; value: T;
} }
export type ReadableStreamReadResult<T> =
type ReadableStreamReadResult<T> =
| ReadableStreamReadValueResult<T> | ReadableStreamReadValueResult<T>
| ReadableStreamReadDoneResult<T>; | ReadableStreamReadDoneResult<T>;
export interface ReadableStreamDefaultReader<R = any> {
interface ReadableStreamDefaultReader<R = any> {
readonly closed: Promise<void>; readonly closed: Promise<void>;
cancel(reason?: any): Promise<void>; cancel(reason?: any): Promise<void>;
read(): Promise<ReadableStreamReadResult<R>>; read(): Promise<ReadableStreamReadResult<R>>;
releaseLock(): void; releaseLock(): void;
} }
export interface UnderlyingSource<R = any> {
interface UnderlyingSource<R = any> {
cancel?: ReadableStreamErrorCallback; cancel?: ReadableStreamErrorCallback;
pull?: ReadableStreamDefaultControllerCallback<R>; pull?: ReadableStreamDefaultControllerCallback<R>;
start?: ReadableStreamDefaultControllerCallback<R>; start?: ReadableStreamDefaultControllerCallback<R>;
type?: undefined; type?: undefined;
} }
export interface ReadableStreamErrorCallback {
interface ReadableStreamErrorCallback {
(reason: any): void | PromiseLike<void>; (reason: any): void | PromiseLike<void>;
} }
export interface ReadableStreamDefaultControllerCallback<R> { interface ReadableStreamDefaultControllerCallback<R> {
(controller: ReadableStreamDefaultController<R>): void | PromiseLike<void>; (controller: ReadableStreamDefaultController<R>): void | PromiseLike<void>;
} }
export interface ReadableStreamDefaultController<R> { interface ReadableStreamDefaultController<R> {
readonly desiredSize: number; readonly desiredSize: number;
enqueue(chunk?: R): void; enqueue(chunk?: R): void;
close(): void; close(): void;
error(e?: any): void; error(e?: any): void;
} }
/** This Streams API interface represents a readable stream of byte data. The /** This Streams API interface represents a readable stream of byte data. The
* Fetch API offers a concrete instance of a ReadableStream through the body * Fetch API offers a concrete instance of a ReadableStream through the body
* property of a Response object. */ * property of a Response object. */
export interface ReadableStream<R = any> { interface ReadableStream<R = any> {
readonly locked: boolean; readonly locked: boolean;
cancel(reason?: any): Promise<void>; cancel(reason?: any): Promise<void>;
getReader(options: { mode: "byob" }): ReadableStreamBYOBReader; // TODO(ry) It doesn't seem like Chrome supports this.
// getReader(options: { mode: "byob" }): ReadableStreamBYOBReader;
getReader(): ReadableStreamDefaultReader<R>; getReader(): ReadableStreamDefaultReader<R>;
/* disabled for now
pipeThrough<T>(
{
writable,
readable
}: {
writable: WritableStream<R>;
readable: ReadableStream<T>;
},
options?: PipeOptions
): ReadableStream<T>;
pipeTo(dest: WritableStream<R>, options?: PipeOptions): Promise<void>;
*/
tee(): [ReadableStream<R>, ReadableStream<R>]; tee(): [ReadableStream<R>, ReadableStream<R>];
} }
export interface ReadableStreamConstructor<R = any> { declare const ReadableStream: {
new (src?: UnderlyingSource<R>): ReadableStream<R>; prototype: ReadableStream;
prototype: ReadableStream<R>; // TODO(ry) This doesn't match lib.dom.d.ts
} new <R = any>(src?: UnderlyingSource<R>): ReadableStream<R>;
};
export interface ReadableStreamReader<R = any> { /** This Streams API interface provides a standard abstraction for writing streaming data to a destination, known as a sink. This object comes with built-in backpressure and queuing. */
cancel(reason: any): Promise<void>; interface WritableStream<W = any> {
read(): Promise<ReadableStreamReadResult<R>>;
releaseLock(): void;
}
export interface ReadableStreamBYOBReader {
readonly closed: Promise<void>;
cancel(reason?: any): Promise<void>;
read<T extends ArrayBufferView>(
view: T
): Promise<ReadableStreamReadResult<T>>;
releaseLock(): void;
}
export interface WritableStream<W = any> {
readonly locked: boolean; readonly locked: boolean;
abort(reason?: any): Promise<void>; abort(reason?: any): Promise<void>;
getWriter(): WritableStreamDefaultWriter<W>; getWriter(): WritableStreamDefaultWriter<W>;
} }
export interface WritableStreamDefaultWriter<W = any> {
interface WritableStreamDefaultWriter<W = any> {
readonly closed: Promise<void>; readonly closed: Promise<void>;
readonly desiredSize: number | null; readonly desiredSize: number | null;
readonly ready: Promise<void>; readonly ready: Promise<void>;
@ -331,8 +303,9 @@ declare namespace __domTypes {
close(): Promise<void>; close(): Promise<void>;
releaseLock(): void; releaseLock(): void;
write(chunk: W): Promise<void>; write(chunk: W): Promise<void>;
} }
export interface DOMStringList {
interface DOMStringList {
/** Returns the number of strings in strings. */ /** Returns the number of strings in strings. */
readonly length: number; readonly length: number;
/** Returns true if strings contains string, and false otherwise. */ /** Returns true if strings contains string, and false otherwise. */
@ -340,12 +313,13 @@ declare namespace __domTypes {
/** Returns the string with index index from strings. */ /** Returns the string with index index from strings. */
item(index: number): string | null; item(index: number): string | null;
[index: number]: string; [index: number]: string;
} }
/** The location (URL) of the object it is linked to. Changes done on it are
/** The location (URL) of the object it is linked to. Changes done on it are
* reflected on the object it relates to. Both the Document and Window * reflected on the object it relates to. Both the Document and Window
* interface have such a linked Location, accessible via Document.location and * interface have such a linked Location, accessible via Document.location and
* Window.location respectively. */ * Window.location respectively. */
export interface Location { declare interface Location {
/** Returns a DOMStringList object listing the origins of the ancestor /** Returns a DOMStringList object listing the origins of the ancestor
* browsing contexts, from the parent browsing context to the top-level * browsing contexts, from the parent browsing context to the top-level
* browsing context. */ * browsing context. */
@ -401,7 +375,6 @@ declare namespace __domTypes {
/** Removes the current page from the session history and navigates to the /** Removes the current page from the session history and navigates to the
* given URL. */ * given URL. */
replace(url: string): void; replace(url: string): void;
}
} }
type BufferSource = ArrayBufferView | ArrayBuffer; type BufferSource = ArrayBufferView | ArrayBuffer;
@ -515,7 +488,7 @@ type FormDataEntryValue = File | string;
* form fields and their values, which can then be easily sent using the * form fields and their values, which can then be easily sent using the
* XMLHttpRequest.send() method. It uses the same format a form would use if the * XMLHttpRequest.send() method. It uses the same format a form would use if the
* encoding type were set to "multipart/form-data". */ * encoding type were set to "multipart/form-data". */
interface FormData extends __domTypes.DomIterable<string, FormDataEntryValue> { interface FormData extends DomIterable<string, FormDataEntryValue> {
append(name: string, value: string | Blob, fileName?: string): void; append(name: string, value: string | Blob, fileName?: string): void;
delete(name: string): void; delete(name: string): void;
get(name: string): FormDataEntryValue | null; get(name: string): FormDataEntryValue | null;
@ -581,7 +554,7 @@ interface Headers {
): void; ): void;
} }
interface Headers extends __domTypes.DomIterable<string, string> { interface Headers extends DomIterable<string, string> {
/** Appends a new value onto an existing header inside a `Headers` object, or /** Appends a new value onto an existing header inside a `Headers` object, or
* adds the header if it does not already exist. * adds the header if it does not already exist.
*/ */

View file

@ -7,19 +7,20 @@
/// <reference lib="deno.shared_globals" /> /// <reference lib="deno.shared_globals" />
/// <reference lib="esnext" /> /// <reference lib="esnext" />
declare interface Window extends WindowOrWorkerGlobalScope { declare interface Window {
window: Window & WindowOrWorkerGlobalScope & typeof globalThis; window: Window & typeof globalThis;
self: Window & WindowOrWorkerGlobalScope & typeof globalThis; self: Window & typeof globalThis;
onload: Function | undefined; onload: Function | undefined;
onunload: Function | undefined; onunload: Function | undefined;
location: Location;
crypto: Crypto; crypto: Crypto;
close: () => void; close: () => void;
closed: boolean; closed: boolean;
Deno: typeof Deno; Deno: typeof Deno;
} }
declare const window: Window & WindowOrWorkerGlobalScope & typeof globalThis; declare const window: Window & typeof globalThis;
declare const self: Window & WindowOrWorkerGlobalScope & typeof globalThis; declare const self: Window & typeof globalThis;
declare const onload: Function | undefined; declare const onload: Function | undefined;
declare const onunload: Function | undefined; declare const onunload: Function | undefined;
declare const crypto: Crypto; declare const crypto: Crypto;

View file

@ -1,15 +1,13 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-interface, @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any */
/// <reference no-default-lib="true" /> /// <reference no-default-lib="true" />
/// <reference lib="deno.shared_globals" /> /// <reference lib="deno.shared_globals" />
/// <reference lib="esnext" /> /// <reference lib="esnext" />
declare interface DedicatedWorkerGlobalScope extends WindowOrWorkerGlobalScope { declare interface DedicatedWorkerGlobalScope {
self: DedicatedWorkerGlobalScope & self: DedicatedWorkerGlobalScope & typeof globalThis;
WindowOrWorkerGlobalScope &
typeof globalThis;
onmessage: (e: { data: any }) => void; onmessage: (e: { data: any }) => void;
onerror: undefined | typeof onerror; onerror: undefined | typeof onerror;
name: typeof __workerMain.name; name: typeof __workerMain.name;
@ -17,9 +15,7 @@ declare interface DedicatedWorkerGlobalScope extends WindowOrWorkerGlobalScope {
postMessage: typeof __workerMain.postMessage; postMessage: typeof __workerMain.postMessage;
} }
declare const self: DedicatedWorkerGlobalScope & declare const self: DedicatedWorkerGlobalScope & typeof globalThis;
WindowOrWorkerGlobalScope &
typeof globalThis;
declare let onmessage: ((e: { data: any }) => Promise<void> | void) | undefined; declare let onmessage: ((e: { data: any }) => Promise<void> | void) | undefined;
declare let onerror: declare let onerror:
| (( | ((
@ -41,4 +37,4 @@ declare namespace __workerMain {
export const name: string; export const name: string;
} }
/* eslint-enable @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-interface, @typescript-eslint/no-explicit-any */ /* eslint-enable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any */

View file

@ -1,16 +1,4 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
[WILDCARD] [WILDCARD]
declare namespace Deno [WILDCARD]
declare namespace Deno { declare const window: Window [WILDCARD]
[WILDCARD]
}
[WILDCARD]
declare interface WindowOrWorkerGlobalScope {
[WILDCARD]
declare interface Window extends WindowOrWorkerGlobalScope {
[WILDCARD]
Deno: typeof Deno;
}
declare const window: Window & WindowOrWorkerGlobalScope & typeof globalThis;
[WILDCARD]