mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-09 11:13:57 +08:00
properly type string enums
The API is defined in terms of strings. TypeScript enums' values are numbers and are not correct for this API. Drop the enums and use the new string union type instead, as it was designed for just this use case.
This commit is contained in:
Vendored
+22
-19
@@ -8,32 +8,35 @@ declare class Request extends Body {
|
||||
method: string;
|
||||
url: string;
|
||||
headers: Headers;
|
||||
context: string|RequestContext;
|
||||
context: RequestContext;
|
||||
referrer: string;
|
||||
mode: string|RequestMode;
|
||||
credentials: string|RequestCredentials;
|
||||
cache: string|RequestCache;
|
||||
mode: RequestMode;
|
||||
credentials: RequestCredentials;
|
||||
cache: RequestCache;
|
||||
}
|
||||
|
||||
interface RequestInit {
|
||||
method?: string;
|
||||
headers?: HeaderInit|{ [index: string]: string };
|
||||
body?: BodyInit;
|
||||
mode?: string|RequestMode;
|
||||
credentials?: string|RequestCredentials;
|
||||
cache?: string|RequestCache;
|
||||
mode?: RequestMode;
|
||||
credentials?: RequestCredentials;
|
||||
cache?: RequestCache;
|
||||
}
|
||||
|
||||
declare enum RequestContext {
|
||||
"audio", "beacon", "cspreport", "download", "embed", "eventsource", "favicon", "fetch",
|
||||
"font", "form", "frame", "hyperlink", "iframe", "image", "imageset", "import",
|
||||
"internal", "location", "manifest", "object", "ping", "plugin", "prefetch", "script",
|
||||
"serviceworker", "sharedworker", "subresource", "style", "track", "video", "worker",
|
||||
"xmlhttprequest", "xslt"
|
||||
}
|
||||
declare enum RequestMode { "same-origin", "no-cors", "cors" }
|
||||
declare enum RequestCredentials { "omit", "same-origin", "include" }
|
||||
declare enum RequestCache { "default", "no-store", "reload", "no-cache", "force-cache", "only-if-cached" }
|
||||
type RequestContext =
|
||||
"audio" | "beacon" | "cspreport" | "download" | "embed" |
|
||||
"eventsource" | "favicon" | "fetch" | "font" | "form" | "frame" |
|
||||
"hyperlink" | "iframe" | "image" | "imageset" | "import" |
|
||||
"internal" | "location" | "manifest" | "object" | "ping" | "plugin" |
|
||||
"prefetch" | "script" | "serviceworker" | "sharedworker" |
|
||||
"subresource" | "style" | "track" | "video" | "worker" |
|
||||
"xmlhttprequest" | "xslt";
|
||||
type RequestMode = "same-origin" | "no-cors" | "cors";
|
||||
type RequestCredentials = "omit" | "same-origin" | "include";
|
||||
type RequestCache =
|
||||
"default" | "no-store" | "reload" | "no-cache" |
|
||||
"force-cache" | "only-if-cached";
|
||||
|
||||
declare class Headers {
|
||||
append(name: string, value: string): void;
|
||||
@@ -58,7 +61,7 @@ declare class Response extends Body {
|
||||
constructor(body?: BodyInit, init?: ResponseInit);
|
||||
error(): Response;
|
||||
redirect(url: string, status: number): Response;
|
||||
type: string|ResponseType;
|
||||
type: ResponseType;
|
||||
url: string;
|
||||
status: number;
|
||||
ok: boolean;
|
||||
@@ -67,7 +70,7 @@ declare class Response extends Body {
|
||||
clone(): Response;
|
||||
}
|
||||
|
||||
declare enum ResponseType { "basic", "cors", "default", "error", "opaque" }
|
||||
type ResponseType = "basic" | "cors" | "default" | "error" | "opaque";
|
||||
|
||||
interface ResponseInit {
|
||||
status: number;
|
||||
|
||||
Reference in New Issue
Block a user