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:
parent
826e899bbc
commit
3204092732
3 changed files with 278 additions and 246 deletions
|
@ -13,7 +13,12 @@
|
|||
"includes": ["**/*.{ts,tsx,js,jsx,json,md}"],
|
||||
"excludes": [
|
||||
".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/tsc/*typescript.js",
|
||||
"gh-pages",
|
||||
|
|
328
cli/dts/lib.deno.shared_globals.d.ts
vendored
328
cli/dts/lib.deno.shared_globals.d.ts
vendored
|
@ -8,128 +8,111 @@
|
|||
/// <reference lib="deno.fetch" />
|
||||
|
||||
declare namespace WebAssembly {
|
||||
interface CompileError {
|
||||
}
|
||||
export class CompileError {
|
||||
constructor();
|
||||
}
|
||||
|
||||
var CompileError: {
|
||||
prototype: CompileError;
|
||||
new(): CompileError;
|
||||
};
|
||||
export class Global {
|
||||
constructor(descriptor: GlobalDescriptor, v?: any);
|
||||
|
||||
interface Global {
|
||||
value: any;
|
||||
valueOf(): any;
|
||||
}
|
||||
value: any;
|
||||
valueOf(): any;
|
||||
}
|
||||
|
||||
var Global: {
|
||||
prototype: Global;
|
||||
new(descriptor: GlobalDescriptor, v?: any): Global;
|
||||
};
|
||||
export class Instance {
|
||||
constructor(module: Module, importObject?: Imports);
|
||||
readonly exports: Exports;
|
||||
}
|
||||
|
||||
interface Instance {
|
||||
readonly exports: Exports;
|
||||
}
|
||||
export class LinkError {
|
||||
constructor();
|
||||
}
|
||||
|
||||
var Instance: {
|
||||
prototype: Instance;
|
||||
new(module: Module, importObject?: Imports): Instance;
|
||||
};
|
||||
export class Memory {
|
||||
constructor(descriptor: MemoryDescriptor);
|
||||
readonly buffer: ArrayBuffer;
|
||||
grow(delta: number): number;
|
||||
}
|
||||
|
||||
interface LinkError {
|
||||
}
|
||||
export class Module {
|
||||
constructor(bytes: BufferSource);
|
||||
static customSections(
|
||||
moduleObject: Module,
|
||||
sectionName: string,
|
||||
): ArrayBuffer[];
|
||||
static exports(moduleObject: Module): ModuleExportDescriptor[];
|
||||
static imports(moduleObject: Module): ModuleImportDescriptor[];
|
||||
}
|
||||
|
||||
var LinkError: {
|
||||
prototype: LinkError;
|
||||
new(): LinkError;
|
||||
};
|
||||
export class RuntimeError {
|
||||
constructor();
|
||||
}
|
||||
|
||||
interface Memory {
|
||||
readonly buffer: ArrayBuffer;
|
||||
grow(delta: number): number;
|
||||
}
|
||||
export class Table {
|
||||
constructor(descriptor: TableDescriptor);
|
||||
readonly length: number;
|
||||
get(index: number): Function | null;
|
||||
grow(delta: number): number;
|
||||
set(index: number, value: Function | null): void;
|
||||
}
|
||||
|
||||
var Memory: {
|
||||
prototype: Memory;
|
||||
new(descriptor: MemoryDescriptor): Memory;
|
||||
};
|
||||
export interface GlobalDescriptor {
|
||||
mutable?: boolean;
|
||||
value: ValueType;
|
||||
}
|
||||
|
||||
interface Module {
|
||||
}
|
||||
export interface MemoryDescriptor {
|
||||
initial: number;
|
||||
maximum?: number;
|
||||
}
|
||||
|
||||
var Module: {
|
||||
prototype: Module;
|
||||
new(bytes: BufferSource): Module;
|
||||
customSections(moduleObject: Module, sectionName: string): ArrayBuffer[];
|
||||
exports(moduleObject: Module): ModuleExportDescriptor[];
|
||||
imports(moduleObject: Module): ModuleImportDescriptor[];
|
||||
};
|
||||
export interface ModuleExportDescriptor {
|
||||
kind: ImportExportKind;
|
||||
name: string;
|
||||
}
|
||||
|
||||
interface RuntimeError {
|
||||
}
|
||||
export interface ModuleImportDescriptor {
|
||||
kind: ImportExportKind;
|
||||
module: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
var RuntimeError: {
|
||||
prototype: RuntimeError;
|
||||
new(): RuntimeError;
|
||||
};
|
||||
export interface TableDescriptor {
|
||||
element: TableKind;
|
||||
initial: number;
|
||||
maximum?: number;
|
||||
}
|
||||
|
||||
interface Table {
|
||||
readonly length: number;
|
||||
get(index: number): Function | null;
|
||||
grow(delta: number): number;
|
||||
set(index: number, value: Function | null): void;
|
||||
}
|
||||
export interface WebAssemblyInstantiatedSource {
|
||||
instance: Instance;
|
||||
module: Module;
|
||||
}
|
||||
|
||||
var Table: {
|
||||
prototype: Table;
|
||||
new(descriptor: TableDescriptor): Table;
|
||||
};
|
||||
|
||||
interface GlobalDescriptor {
|
||||
mutable?: boolean;
|
||||
value: ValueType;
|
||||
}
|
||||
|
||||
interface MemoryDescriptor {
|
||||
initial: number;
|
||||
maximum?: number;
|
||||
}
|
||||
|
||||
interface ModuleExportDescriptor {
|
||||
kind: ImportExportKind;
|
||||
name: string;
|
||||
}
|
||||
|
||||
interface ModuleImportDescriptor {
|
||||
kind: ImportExportKind;
|
||||
module: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
interface TableDescriptor {
|
||||
element: TableKind;
|
||||
initial: number;
|
||||
maximum?: number;
|
||||
}
|
||||
|
||||
interface WebAssemblyInstantiatedSource {
|
||||
instance: Instance;
|
||||
module: Module;
|
||||
}
|
||||
|
||||
type ImportExportKind = "function" | "global" | "memory" | "table";
|
||||
type TableKind = "anyfunc";
|
||||
type ValueType = "f32" | "f64" | "i32" | "i64";
|
||||
type ExportValue = Function | Global | Memory | Table;
|
||||
type Exports = Record<string, ExportValue>;
|
||||
type ImportValue = ExportValue | number;
|
||||
type ModuleImports = Record<string, ImportValue>;
|
||||
type Imports = Record<string, ModuleImports>;
|
||||
function compile(bytes: BufferSource): Promise<Module>;
|
||||
function compileStreaming(source: Response | Promise<Response>): Promise<Module>;
|
||||
function instantiate(bytes: BufferSource, importObject?: Imports): Promise<WebAssemblyInstantiatedSource>;
|
||||
function instantiate(moduleObject: Module, importObject?: Imports): Promise<Instance>;
|
||||
function instantiateStreaming(response: Response | PromiseLike<Response>, importObject?: Imports): Promise<WebAssemblyInstantiatedSource>;
|
||||
function validate(bytes: BufferSource): boolean;
|
||||
export type ImportExportKind = "function" | "global" | "memory" | "table";
|
||||
export type TableKind = "anyfunc";
|
||||
export type ValueType = "f32" | "f64" | "i32" | "i64";
|
||||
export type ExportValue = Function | Global | Memory | Table;
|
||||
export type Exports = Record<string, ExportValue>;
|
||||
export type ImportValue = ExportValue | number;
|
||||
export type ModuleImports = Record<string, ImportValue>;
|
||||
export type Imports = Record<string, ModuleImports>;
|
||||
export function compile(bytes: BufferSource): Promise<Module>;
|
||||
export function compileStreaming(
|
||||
source: Response | Promise<Response>,
|
||||
): Promise<Module>;
|
||||
export function instantiate(
|
||||
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
|
||||
|
@ -286,35 +269,12 @@ declare interface Crypto {
|
|||
): 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.
|
||||
*
|
||||
* ```ts
|
||||
|
@ -456,16 +416,12 @@ interface URLSearchParams {
|
|||
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. */
|
||||
interface URL {
|
||||
declare class URL {
|
||||
constructor(url: string, base?: string | URL);
|
||||
createObjectURL(object: any): string;
|
||||
revokeObjectURL(url: string): void;
|
||||
|
||||
hash: string;
|
||||
host: string;
|
||||
hostname: string;
|
||||
|
@ -482,13 +438,6 @@ interface URL {
|
|||
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 {
|
||||
data?: any;
|
||||
origin?: string;
|
||||
|
@ -593,7 +542,9 @@ declare class Worker extends EventTarget {
|
|||
|
||||
declare type PerformanceEntryList = PerformanceEntry[];
|
||||
|
||||
declare interface Performance {
|
||||
declare class Performance {
|
||||
constructor();
|
||||
|
||||
/** Removes the stored timestamp with the associated name. */
|
||||
clearMarks(markName?: string): void;
|
||||
|
||||
|
@ -633,11 +584,6 @@ declare interface Performance {
|
|||
now(): number;
|
||||
}
|
||||
|
||||
declare const Performance: {
|
||||
prototype: Performance;
|
||||
new (): Performance;
|
||||
};
|
||||
|
||||
declare const performance: Performance;
|
||||
|
||||
declare interface PerformanceMarkOptions {
|
||||
|
@ -697,19 +643,15 @@ declare class PerformanceMeasure extends PerformanceEntry {
|
|||
/** Events measuring progress of an underlying process, like an HTTP request
|
||||
* (for an XMLHttpRequest, or the loading of the underlying resource of an
|
||||
* <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 loaded: number;
|
||||
readonly target: T | null;
|
||||
readonly total: number;
|
||||
}
|
||||
|
||||
declare var ProgressEvent: {
|
||||
prototype: ProgressEvent;
|
||||
new(type:string, eventInitDict?: ProgressEventInit): ProgressEvent;
|
||||
};
|
||||
|
||||
interface CustomEventInit<T = any> extends EventInit {
|
||||
declare interface CustomEventInit<T = any> extends EventInit {
|
||||
detail?: T;
|
||||
}
|
||||
|
||||
|
@ -734,7 +676,8 @@ interface CloseEventInit extends EventInit {
|
|||
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.
|
||||
*/
|
||||
|
@ -749,20 +692,22 @@ interface CloseEvent extends Event {
|
|||
readonly wasClean: boolean;
|
||||
}
|
||||
|
||||
declare var CloseEvent: {
|
||||
prototype: CloseEvent;
|
||||
new(type: string, eventInitDict?: CloseEventInit): CloseEvent;
|
||||
};
|
||||
|
||||
interface WebSocketEventMap {
|
||||
"close": CloseEvent;
|
||||
"error": Event;
|
||||
"message": MessageEvent;
|
||||
"open": Event;
|
||||
close: CloseEvent;
|
||||
error: Event;
|
||||
message: MessageEvent;
|
||||
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. */
|
||||
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:
|
||||
*
|
||||
|
@ -807,19 +752,26 @@ interface WebSocket extends EventTarget {
|
|||
readonly CLOSING: number;
|
||||
readonly CONNECTING: number;
|
||||
readonly OPEN: number;
|
||||
addEventListener<K extends keyof WebSocketEventMap>(type: K, listener: (this: WebSocket, ev: WebSocketEventMap[K]) => any, 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;
|
||||
addEventListener<K extends keyof WebSocketEventMap>(
|
||||
type: K,
|
||||
listener: (this: WebSocket, ev: WebSocketEventMap[K]) => any,
|
||||
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";
|
||||
|
|
189
op_crates/fetch/lib.deno_fetch.d.ts
vendored
189
op_crates/fetch/lib.deno_fetch.d.ts
vendored
|
@ -102,7 +102,7 @@ interface QueuingStrategy<T = any> {
|
|||
}
|
||||
|
||||
/** This Streams API interface provides a built-in byte length queuing strategy
|
||||
* that can be used when constructing streams. */
|
||||
* that can be used when constructing streams. */
|
||||
declare class CountQueuingStrategy implements QueuingStrategy {
|
||||
constructor(options: { highWaterMark: number });
|
||||
highWaterMark: number;
|
||||
|
@ -117,8 +117,8 @@ declare class ByteLengthQueuingStrategy
|
|||
}
|
||||
|
||||
/** This Streams API interface represents a readable stream of byte data. The
|
||||
* Fetch API offers a concrete instance of a ReadableStream through the body
|
||||
* property of a Response object. */
|
||||
* Fetch API offers a concrete instance of a ReadableStream through the body
|
||||
* property of a Response object. */
|
||||
interface ReadableStream<R = any> {
|
||||
readonly locked: boolean;
|
||||
cancel(reason?: any): Promise<void>;
|
||||
|
@ -142,7 +142,7 @@ interface ReadableStream<R = any> {
|
|||
}): AsyncIterableIterator<R>;
|
||||
}
|
||||
|
||||
declare var ReadableStream: {
|
||||
declare const ReadableStream: {
|
||||
prototype: ReadableStream;
|
||||
new (
|
||||
underlyingSource: UnderlyingByteSource,
|
||||
|
@ -183,8 +183,8 @@ interface UnderlyingSink<W = 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. */
|
||||
* streaming data to a destination, known as a sink. This object comes with
|
||||
* built-in backpressure and queuing. */
|
||||
declare class WritableStream<W = any> {
|
||||
constructor(
|
||||
underlyingSink?: UnderlyingSink<W>,
|
||||
|
@ -197,17 +197,17 @@ declare class WritableStream<W = any> {
|
|||
}
|
||||
|
||||
/** This Streams API interface represents a controller allowing control of a
|
||||
* WritableStream's state. When constructing a WritableStream, the underlying
|
||||
* sink is given a corresponding WritableStreamDefaultController instance to
|
||||
* manipulate. */
|
||||
* WritableStream's state. When constructing a WritableStream, the underlying
|
||||
* sink is given a corresponding WritableStreamDefaultController instance to
|
||||
* manipulate. */
|
||||
interface WritableStreamDefaultController {
|
||||
error(error?: any): void;
|
||||
}
|
||||
|
||||
/** This Streams API interface is the object returned by
|
||||
* WritableStream.getWriter() and once created locks the < writer to the
|
||||
* WritableStream ensuring that no other streams can write to the underlying
|
||||
* sink. */
|
||||
* WritableStream.getWriter() and once created locks the < writer to the
|
||||
* WritableStream ensuring that no other streams can write to the underlying
|
||||
* sink. */
|
||||
interface WritableStreamDefaultWriter<W = any> {
|
||||
readonly closed: Promise<void>;
|
||||
readonly desiredSize: number | null;
|
||||
|
@ -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. */
|
||||
interface Blob {
|
||||
declare class Blob {
|
||||
constructor(blobParts?: BlobPart[], options?: BlobPropertyBag);
|
||||
|
||||
readonly size: number;
|
||||
readonly type: string;
|
||||
arrayBuffer(): Promise<ArrayBuffer>;
|
||||
|
@ -271,49 +273,50 @@ interface Blob {
|
|||
text(): Promise<string>;
|
||||
}
|
||||
|
||||
declare const Blob: {
|
||||
prototype: Blob;
|
||||
new (blobParts?: BlobPart[], options?: BlobPropertyBag): Blob;
|
||||
};
|
||||
|
||||
interface FilePropertyBag extends BlobPropertyBag {
|
||||
lastModified?: number;
|
||||
}
|
||||
|
||||
/** Provides information about files and allows JavaScript in a web page to
|
||||
* access their content. */
|
||||
interface File extends Blob {
|
||||
* access their content. */
|
||||
declare class File extends Blob {
|
||||
constructor(
|
||||
fileBits: BlobPart[],
|
||||
fileName: string,
|
||||
options?: FilePropertyBag,
|
||||
);
|
||||
|
||||
readonly lastModified: number;
|
||||
readonly name: string;
|
||||
}
|
||||
|
||||
declare const File: {
|
||||
prototype: File;
|
||||
new (fileBits: BlobPart[], fileName: string, options?: FilePropertyBag): File;
|
||||
};
|
||||
|
||||
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
|
||||
* XMLHttpRequest.send() method. It uses the same format a form would use if the
|
||||
* 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;
|
||||
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<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 {
|
||||
/** A simple getter used to expose a `ReadableStream` of the body contents. */
|
||||
readonly body: ReadableStream<Uint8Array> | null;
|
||||
|
@ -364,7 +367,9 @@ interface Headers {
|
|||
): 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
|
||||
* adds the header if it does not already exist.
|
||||
*/
|
||||
|
@ -406,11 +411,6 @@ interface Headers extends DomIterable<string, string> {
|
|||
[Symbol.iterator](): IterableIterator<[string, string]>;
|
||||
}
|
||||
|
||||
declare const Headers: {
|
||||
prototype: Headers;
|
||||
new (init?: HeadersInit): Headers;
|
||||
};
|
||||
|
||||
type RequestInfo = Request | string;
|
||||
type RequestCache =
|
||||
| "default"
|
||||
|
@ -524,7 +524,9 @@ interface RequestInit {
|
|||
}
|
||||
|
||||
/** 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
|
||||
* indicating how the request will interact with the browser's cache when
|
||||
|
@ -608,28 +610,101 @@ interface Request extends Body {
|
|||
*/
|
||||
readonly url: string;
|
||||
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: {
|
||||
prototype: Request;
|
||||
new (input: RequestInfo, init?: RequestInit): Request;
|
||||
};
|
||||
interface ResponseInit {
|
||||
headers?: HeadersInit;
|
||||
status?: number;
|
||||
statusText?: string;
|
||||
}
|
||||
|
||||
declare const Response: {
|
||||
prototype: Response;
|
||||
new (body?: BodyInit | null, init?: ResponseInit): Response;
|
||||
error(): Response;
|
||||
redirect(url: string, status?: number): Response;
|
||||
};
|
||||
type ResponseType =
|
||||
| "basic"
|
||||
| "cors"
|
||||
| "default"
|
||||
| "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
|
||||
* Response to that request, whether it is successful or not.
|
||||
*
|
||||
* const response = await fetch("http://my.json.host/data.json");
|
||||
* console.log(response.status); // e.g. 200
|
||||
* console.log(response.statusText); // e.g. "OK"
|
||||
* const jsonData = await response.json();
|
||||
*/
|
||||
* Response to that request, whether it is successful or not.
|
||||
*
|
||||
* const response = await fetch("http://my.json.host/data.json");
|
||||
* console.log(response.status); // e.g. 200
|
||||
* console.log(response.statusText); // e.g. "OK"
|
||||
* const jsonData = await response.json();
|
||||
*/
|
||||
declare function fetch(
|
||||
input: Request | URL | string,
|
||||
init?: RequestInit,
|
||||
|
|
Loading…
Reference in a new issue