mirror of
https://github.com/denoland/deno.git
synced 2025-09-27 04:39:10 +00:00
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.
This commit is contained in:
parent
e8a866ca8a
commit
d632cce129
15 changed files with 735 additions and 393 deletions
183
ext/fetch/lib.deno_fetch.d.ts
vendored
183
ext/fetch/lib.deno_fetch.d.ts
vendored
|
@ -6,7 +6,7 @@
|
|||
/// <reference lib="esnext" />
|
||||
|
||||
/** @category DOM APIs */
|
||||
interface DomIterable<K, V> {
|
||||
declare interface DomIterable<K, V> {
|
||||
keys(): IterableIterator<K>;
|
||||
values(): IterableIterator<V>;
|
||||
entries(): IterableIterator<[K, V]>;
|
||||
|
@ -18,7 +18,7 @@ interface DomIterable<K, V> {
|
|||
}
|
||||
|
||||
/** @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<string, FormDataEntryValue> {
|
||||
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;
|
||||
}
|
||||
|
||||
/** @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<Uint8Array> | 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<string, string>;
|
||||
declare type HeadersInit = Iterable<string[]> | Record<string, string>;
|
||||
|
||||
/** 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<string, string>;
|
|||
*
|
||||
* @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<string, string> {
|
||||
constructor(init?: HeadersInit);
|
||||
|
||||
declare interface Headers extends DomIterable<string, string> {
|
||||
/** 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<string, string> {
|
|||
* 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<string>;
|
||||
/** 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<string>;
|
||||
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<Uint8Array>
|
||||
| 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<Uint8Array> | 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<ArrayBuffer>;
|
||||
/** Takes a `Request` stream and reads it to completion. It returns a promise
|
||||
* that resolves with a `Blob`.
|
||||
*/
|
||||
blob(): Promise<Blob>;
|
||||
/** Takes a `Request` stream and reads it to completion. It returns a promise
|
||||
* that resolves with a `FormData` object.
|
||||
*/
|
||||
formData(): Promise<FormData>;
|
||||
/** 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<any>;
|
||||
/** Takes a `Request` stream and reads it to completion. It returns a promise
|
||||
* that resolves with a `USVString` (text).
|
||||
*/
|
||||
text(): Promise<string>;
|
||||
}
|
||||
|
||||
/** 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<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>;
|
||||
}
|
||||
|
||||
/** 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.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue