1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-25 15:29:32 -05:00

refactor: class instead of var+interface in d.ts (#7514)

This commit is contained in:
Luca Casonato 2020-09-25 16:21:34 +02:00 committed by GitHub
parent 826e899bbc
commit 3204092732
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 278 additions and 246 deletions

View file

@ -13,7 +13,12 @@
"includes": ["**/*.{ts,tsx,js,jsx,json,md}"], "includes": ["**/*.{ts,tsx,js,jsx,json,md}"],
"excludes": [ "excludes": [
".cargo_home", ".cargo_home",
"cli/dts", "cli/dts/lib.d.ts",
"cli/dts/lib.dom*",
"cli/dts/lib.es*",
"cli/dts/lib.scripthost.d.ts",
"cli/dts/lib.webworker*.d.ts",
"cli/dts/typescript.d.ts",
"cli/tests/encoding", "cli/tests/encoding",
"cli/tsc/*typescript.js", "cli/tsc/*typescript.js",
"gh-pages", "gh-pages",

View file

@ -8,128 +8,111 @@
/// <reference lib="deno.fetch" /> /// <reference lib="deno.fetch" />
declare namespace WebAssembly { declare namespace WebAssembly {
interface CompileError { export class CompileError {
constructor();
} }
var CompileError: { export class Global {
prototype: CompileError; constructor(descriptor: GlobalDescriptor, v?: any);
new(): CompileError;
};
interface Global {
value: any; value: any;
valueOf(): any; valueOf(): any;
} }
var Global: { export class Instance {
prototype: Global; constructor(module: Module, importObject?: Imports);
new(descriptor: GlobalDescriptor, v?: any): Global;
};
interface Instance {
readonly exports: Exports; readonly exports: Exports;
} }
var Instance: { export class LinkError {
prototype: Instance; constructor();
new(module: Module, importObject?: Imports): Instance;
};
interface LinkError {
} }
var LinkError: { export class Memory {
prototype: LinkError; constructor(descriptor: MemoryDescriptor);
new(): LinkError;
};
interface Memory {
readonly buffer: ArrayBuffer; readonly buffer: ArrayBuffer;
grow(delta: number): number; grow(delta: number): number;
} }
var Memory: { export class Module {
prototype: Memory; constructor(bytes: BufferSource);
new(descriptor: MemoryDescriptor): Memory; static customSections(
}; moduleObject: Module,
sectionName: string,
interface Module { ): ArrayBuffer[];
static exports(moduleObject: Module): ModuleExportDescriptor[];
static imports(moduleObject: Module): ModuleImportDescriptor[];
} }
var Module: { export class RuntimeError {
prototype: Module; constructor();
new(bytes: BufferSource): Module;
customSections(moduleObject: Module, sectionName: string): ArrayBuffer[];
exports(moduleObject: Module): ModuleExportDescriptor[];
imports(moduleObject: Module): ModuleImportDescriptor[];
};
interface RuntimeError {
} }
var RuntimeError: { export class Table {
prototype: RuntimeError; constructor(descriptor: TableDescriptor);
new(): RuntimeError;
};
interface Table {
readonly length: number; readonly length: number;
get(index: number): Function | null; get(index: number): Function | null;
grow(delta: number): number; grow(delta: number): number;
set(index: number, value: Function | null): void; set(index: number, value: Function | null): void;
} }
var Table: { export interface GlobalDescriptor {
prototype: Table;
new(descriptor: TableDescriptor): Table;
};
interface GlobalDescriptor {
mutable?: boolean; mutable?: boolean;
value: ValueType; value: ValueType;
} }
interface MemoryDescriptor { export interface MemoryDescriptor {
initial: number; initial: number;
maximum?: number; maximum?: number;
} }
interface ModuleExportDescriptor { export interface ModuleExportDescriptor {
kind: ImportExportKind; kind: ImportExportKind;
name: string; name: string;
} }
interface ModuleImportDescriptor { export interface ModuleImportDescriptor {
kind: ImportExportKind; kind: ImportExportKind;
module: string; module: string;
name: string; name: string;
} }
interface TableDescriptor { export interface TableDescriptor {
element: TableKind; element: TableKind;
initial: number; initial: number;
maximum?: number; maximum?: number;
} }
interface WebAssemblyInstantiatedSource { export interface WebAssemblyInstantiatedSource {
instance: Instance; instance: Instance;
module: Module; module: Module;
} }
type ImportExportKind = "function" | "global" | "memory" | "table"; export type ImportExportKind = "function" | "global" | "memory" | "table";
type TableKind = "anyfunc"; export type TableKind = "anyfunc";
type ValueType = "f32" | "f64" | "i32" | "i64"; export type ValueType = "f32" | "f64" | "i32" | "i64";
type ExportValue = Function | Global | Memory | Table; export type ExportValue = Function | Global | Memory | Table;
type Exports = Record<string, ExportValue>; export type Exports = Record<string, ExportValue>;
type ImportValue = ExportValue | number; export type ImportValue = ExportValue | number;
type ModuleImports = Record<string, ImportValue>; export type ModuleImports = Record<string, ImportValue>;
type Imports = Record<string, ModuleImports>; export type Imports = Record<string, ModuleImports>;
function compile(bytes: BufferSource): Promise<Module>; export function compile(bytes: BufferSource): Promise<Module>;
function compileStreaming(source: Response | Promise<Response>): Promise<Module>; export function compileStreaming(
function instantiate(bytes: BufferSource, importObject?: Imports): Promise<WebAssemblyInstantiatedSource>; source: Response | Promise<Response>,
function instantiate(moduleObject: Module, importObject?: Imports): Promise<Instance>; ): Promise<Module>;
function instantiateStreaming(response: Response | PromiseLike<Response>, importObject?: Imports): Promise<WebAssemblyInstantiatedSource>; export function instantiate(
function validate(bytes: BufferSource): boolean; bytes: BufferSource,
importObject?: Imports,
): Promise<WebAssemblyInstantiatedSource>;
export function instantiate(
moduleObject: Module,
importObject?: Imports,
): Promise<Instance>;
export function instantiateStreaming(
response: Response | PromiseLike<Response>,
importObject?: Imports,
): Promise<WebAssemblyInstantiatedSource>;
export function validate(bytes: BufferSource): boolean;
} }
/** Sets a timer which executes a function once after the timer expires. Returns /** Sets a timer which executes a function once after the timer expires. Returns
@ -286,35 +269,12 @@ declare interface Crypto {
): T; ): T;
} }
declare class URLSearchParams {
constructor(
init?: string[][] | Record<string, string> | string | URLSearchParams,
);
static toString(): string;
interface ResponseInit {
headers?: HeadersInit;
status?: number;
statusText?: string;
}
type ResponseType =
| "basic"
| "cors"
| "default"
| "error"
| "opaque"
| "opaqueredirect";
/** This Fetch API interface represents the response to a request. */
interface Response extends Body {
readonly headers: Headers;
readonly ok: boolean;
readonly redirected: boolean;
readonly status: number;
readonly statusText: string;
readonly trailer: Promise<Headers>;
readonly type: ResponseType;
readonly url: string;
clone(): Response;
}
interface URLSearchParams {
/** Appends a specified key/value pair as a new search parameter. /** Appends a specified key/value pair as a new search parameter.
* *
* ```ts * ```ts
@ -456,16 +416,12 @@ interface URLSearchParams {
toString(): string; toString(): string;
} }
declare const URLSearchParams: {
prototype: URLSearchParams;
new (
init?: string[][] | Record<string, string> | string | URLSearchParams,
): URLSearchParams;
toString(): string;
};
/** The URL interface represents an object providing static methods used for creating object URLs. */ /** The URL interface represents an object providing static methods used for creating object URLs. */
interface URL { declare class URL {
constructor(url: string, base?: string | URL);
createObjectURL(object: any): string;
revokeObjectURL(url: string): void;
hash: string; hash: string;
host: string; host: string;
hostname: string; hostname: string;
@ -482,13 +438,6 @@ interface URL {
toJSON(): string; toJSON(): string;
} }
declare const URL: {
prototype: URL;
new (url: string, base?: string | URL): URL;
createObjectURL(object: any): string;
revokeObjectURL(url: string): void;
};
interface MessageEventInit extends EventInit { interface MessageEventInit extends EventInit {
data?: any; data?: any;
origin?: string; origin?: string;
@ -593,7 +542,9 @@ declare class Worker extends EventTarget {
declare type PerformanceEntryList = PerformanceEntry[]; declare type PerformanceEntryList = PerformanceEntry[];
declare interface Performance { declare class Performance {
constructor();
/** Removes the stored timestamp with the associated name. */ /** Removes the stored timestamp with the associated name. */
clearMarks(markName?: string): void; clearMarks(markName?: string): void;
@ -633,11 +584,6 @@ declare interface Performance {
now(): number; now(): number;
} }
declare const Performance: {
prototype: Performance;
new (): Performance;
};
declare const performance: Performance; declare const performance: Performance;
declare interface PerformanceMarkOptions { declare interface PerformanceMarkOptions {
@ -697,19 +643,15 @@ declare class PerformanceMeasure extends PerformanceEntry {
/** Events measuring progress of an underlying process, like an HTTP request /** Events measuring progress of an underlying process, like an HTTP request
* (for an XMLHttpRequest, or the loading of the underlying resource of an * (for an XMLHttpRequest, or the loading of the underlying resource of an
* <img>, <audio>, <video>, <style> or <link>). */ * <img>, <audio>, <video>, <style> or <link>). */
interface ProgressEvent<T extends EventTarget = EventTarget> extends Event { declare class ProgressEvent<T extends EventTarget = EventTarget> extends Event {
constructor(type: string, eventInitDict?: ProgressEventInit);
readonly lengthComputable: boolean; readonly lengthComputable: boolean;
readonly loaded: number; readonly loaded: number;
readonly target: T | null; readonly target: T | null;
readonly total: number; readonly total: number;
} }
declare var ProgressEvent: { declare interface CustomEventInit<T = any> extends EventInit {
prototype: ProgressEvent;
new(type:string, eventInitDict?: ProgressEventInit): ProgressEvent;
};
interface CustomEventInit<T = any> extends EventInit {
detail?: T; detail?: T;
} }
@ -734,7 +676,8 @@ interface CloseEventInit extends EventInit {
wasClean?: boolean; wasClean?: boolean;
} }
interface CloseEvent extends Event { declare class CloseEvent extends Event {
constructor(type: string, eventInitDict?: CloseEventInit);
/** /**
* Returns the WebSocket connection close code provided by the server. * Returns the WebSocket connection close code provided by the server.
*/ */
@ -749,20 +692,22 @@ interface CloseEvent extends Event {
readonly wasClean: boolean; readonly wasClean: boolean;
} }
declare var CloseEvent: {
prototype: CloseEvent;
new(type: string, eventInitDict?: CloseEventInit): CloseEvent;
};
interface WebSocketEventMap { interface WebSocketEventMap {
"close": CloseEvent; close: CloseEvent;
"error": Event; error: Event;
"message": MessageEvent; message: MessageEvent;
"open": Event; open: Event;
} }
/** Provides the API for creating and managing a WebSocket connection to a server, as well as for sending and receiving data on the connection. */ /** Provides the API for creating and managing a WebSocket connection to a server, as well as for sending and receiving data on the connection. */
interface WebSocket extends EventTarget { declare class WebSocket extends EventTarget {
constructor(url: string, protocols?: string | string[]);
static readonly CLOSED: number;
static readonly CLOSING: number;
static readonly CONNECTING: number;
static readonly OPEN: number;
/** /**
* Returns a string that indicates how binary data from the WebSocket object is exposed to scripts: * Returns a string that indicates how binary data from the WebSocket object is exposed to scripts:
* *
@ -807,19 +752,26 @@ interface WebSocket extends EventTarget {
readonly CLOSING: number; readonly CLOSING: number;
readonly CONNECTING: number; readonly CONNECTING: number;
readonly OPEN: number; readonly OPEN: number;
addEventListener<K extends keyof WebSocketEventMap>(type: K, listener: (this: WebSocket, ev: WebSocketEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; addEventListener<K extends keyof WebSocketEventMap>(
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void; type: K,
removeEventListener<K extends keyof WebSocketEventMap>(type: K, listener: (this: WebSocket, ev: WebSocketEventMap[K]) => any, options?: boolean | EventListenerOptions): void; listener: (this: WebSocket, ev: WebSocketEventMap[K]) => any,
removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void; options?: boolean | AddEventListenerOptions,
): void;
addEventListener(
type: string,
listener: EventListenerOrEventListenerObject,
options?: boolean | AddEventListenerOptions,
): void;
removeEventListener<K extends keyof WebSocketEventMap>(
type: K,
listener: (this: WebSocket, ev: WebSocketEventMap[K]) => any,
options?: boolean | EventListenerOptions,
): void;
removeEventListener(
type: string,
listener: EventListenerOrEventListenerObject,
options?: boolean | EventListenerOptions,
): void;
} }
declare var WebSocket: {
prototype: WebSocket;
new(url: string, protocols?: string | string[]): WebSocket;
readonly CLOSED: number;
readonly CLOSING: number;
readonly CONNECTING: number;
readonly OPEN: number;
};
type BinaryType = "arraybuffer" | "blob"; type BinaryType = "arraybuffer" | "blob";

View file

@ -142,7 +142,7 @@ interface ReadableStream<R = any> {
}): AsyncIterableIterator<R>; }): AsyncIterableIterator<R>;
} }
declare var ReadableStream: { declare const ReadableStream: {
prototype: ReadableStream; prototype: ReadableStream;
new ( new (
underlyingSource: UnderlyingByteSource, underlyingSource: UnderlyingByteSource,
@ -262,7 +262,9 @@ interface BlobPropertyBag {
} }
/** A file-like object of immutable, raw data. Blobs represent data that isn't necessarily in a JavaScript-native format. The File interface is based on Blob, inheriting blob functionality and expanding it to support files on the user's system. */ /** A file-like object of immutable, raw data. Blobs represent data that isn't necessarily in a JavaScript-native format. The File interface is based on Blob, inheriting blob functionality and expanding it to support files on the user's system. */
interface Blob { declare class Blob {
constructor(blobParts?: BlobPart[], options?: BlobPropertyBag);
readonly size: number; readonly size: number;
readonly type: string; readonly type: string;
arrayBuffer(): Promise<ArrayBuffer>; arrayBuffer(): Promise<ArrayBuffer>;
@ -271,49 +273,50 @@ interface Blob {
text(): Promise<string>; text(): Promise<string>;
} }
declare const Blob: {
prototype: Blob;
new (blobParts?: BlobPart[], options?: BlobPropertyBag): Blob;
};
interface FilePropertyBag extends BlobPropertyBag { interface FilePropertyBag extends BlobPropertyBag {
lastModified?: number; lastModified?: number;
} }
/** Provides information about files and allows JavaScript in a web page to /** Provides information about files and allows JavaScript in a web page to
* access their content. */ * access their content. */
interface File extends Blob { declare class File extends Blob {
constructor(
fileBits: BlobPart[],
fileName: string,
options?: FilePropertyBag,
);
readonly lastModified: number; readonly lastModified: number;
readonly name: string; readonly name: string;
} }
declare const File: {
prototype: File;
new (fileBits: BlobPart[], fileName: string, options?: FilePropertyBag): File;
};
type FormDataEntryValue = File | string; type FormDataEntryValue = File | string;
/** Provides a way to easily construct a set of key/value pairs representing /** 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 * 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 DomIterable<string, FormDataEntryValue> { declare class FormData implements DomIterable<string, FormDataEntryValue> {
// TODO(ry) FormData constructor is non-standard.
// new(form?: HTMLFormElement): FormData;
constructor();
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;
getAll(name: string): FormDataEntryValue[]; getAll(name: string): FormDataEntryValue[];
has(name: string): boolean; has(name: string): boolean;
set(name: string, value: string | Blob, fileName?: string): void; set(name: string, value: string | Blob, fileName?: string): void;
keys(): IterableIterator<string>;
values(): IterableIterator<string>;
entries(): IterableIterator<[string, FormDataEntryValue]>;
[Symbol.iterator](): IterableIterator<[string, FormDataEntryValue]>;
forEach(
callback: (value: FormDataEntryValue, key: string, parent: this) => void,
thisArg?: any,
): void;
} }
declare const FormData: {
prototype: FormData;
// TODO(ry) FormData constructor is non-standard.
// new(form?: HTMLFormElement): FormData;
new (): FormData;
};
interface Body { interface Body {
/** A simple getter used to expose a `ReadableStream` of the body contents. */ /** A simple getter used to expose a `ReadableStream` of the body contents. */
readonly body: ReadableStream<Uint8Array> | null; readonly body: ReadableStream<Uint8Array> | null;
@ -364,7 +367,9 @@ interface Headers {
): void; ): void;
} }
interface Headers extends DomIterable<string, string> { declare class Headers implements DomIterable<string, string> {
constructor(init?: HeadersInit);
/** 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.
*/ */
@ -406,11 +411,6 @@ interface Headers extends DomIterable<string, string> {
[Symbol.iterator](): IterableIterator<[string, string]>; [Symbol.iterator](): IterableIterator<[string, string]>;
} }
declare const Headers: {
prototype: Headers;
new (init?: HeadersInit): Headers;
};
type RequestInfo = Request | string; type RequestInfo = Request | string;
type RequestCache = type RequestCache =
| "default" | "default"
@ -524,7 +524,9 @@ interface RequestInit {
} }
/** This Fetch API interface represents a resource request. */ /** This Fetch API interface represents a resource request. */
interface Request extends Body { declare class Request implements Body {
constructor(input: RequestInfo, init?: RequestInit);
/** /**
* Returns the cache mode associated with request, which is a string * Returns the cache mode associated with request, which is a string
* indicating how the request will interact with the browser's cache when * indicating how the request will interact with the browser's cache when
@ -608,19 +610,92 @@ interface Request extends Body {
*/ */
readonly url: string; readonly url: string;
clone(): Request; clone(): Request;
/** A simple getter used to expose a `ReadableStream` of the body contents. */
readonly body: ReadableStream<Uint8Array> | 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<ArrayBuffer>;
/** Takes a `Response` stream and reads it to completion. It returns a promise
* that resolves with a `Blob`.
*/
blob(): Promise<Blob>;
/** Takes a `Response` stream and reads it to completion. It returns a promise
* that resolves with a `FormData` object.
*/
formData(): Promise<FormData>;
/** 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<any>;
/** Takes a `Response` stream and reads it to completion. It returns a promise
* that resolves with a `USVString` (text).
*/
text(): Promise<string>;
} }
declare const Request: { interface ResponseInit {
prototype: Request; headers?: HeadersInit;
new (input: RequestInfo, init?: RequestInit): Request; status?: number;
}; statusText?: string;
}
declare const Response: { type ResponseType =
prototype: Response; | "basic"
new (body?: BodyInit | null, init?: ResponseInit): Response; | "cors"
error(): Response; | "default"
redirect(url: string, status?: number): Response; | "error"
}; | "opaque"
| "opaqueredirect";
/** This Fetch API interface represents the response to a request. */
declare class Response implements Body {
constructor(body?: BodyInit | null, init?: ResponseInit);
static error(): Response;
static redirect(url: string, status?: number): Response;
readonly headers: Headers;
readonly ok: boolean;
readonly redirected: boolean;
readonly status: number;
readonly statusText: string;
readonly trailer: Promise<Headers>;
readonly type: ResponseType;
readonly url: string;
clone(): Response;
/** A simple getter used to expose a `ReadableStream` of the body contents. */
readonly body: ReadableStream<Uint8Array> | 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<ArrayBuffer>;
/** Takes a `Response` stream and reads it to completion. It returns a promise
* that resolves with a `Blob`.
*/
blob(): Promise<Blob>;
/** Takes a `Response` stream and reads it to completion. It returns a promise
* that resolves with a `FormData` object.
*/
formData(): Promise<FormData>;
/** 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<any>;
/** Takes a `Response` stream and reads it to completion. It returns a promise
* that resolves with a `USVString` (text).
*/
text(): Promise<string>;
}
/** Fetch a resource from the network. It returns a Promise that resolves to the /** Fetch a resource from the network. It returns a Promise that resolves to the
* Response to that request, whether it is successful or not. * Response to that request, whether it is successful or not.