diff options
author | Kitson Kelly <me@kitsonkelly.com> | 2018-10-23 22:43:43 +1100 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2018-10-23 04:43:43 -0700 |
commit | c0492ef061afd5af2044d5952432d223615841a7 (patch) | |
tree | f7c0c30e4fd25868b4d3f8e1913d04a655cebc2a /js/dom_types.ts | |
parent | de85f9443598ba5a75102be77f6f27a5cf0c0a9a (diff) |
Make Headers more idiomatic (#1062)
Diffstat (limited to 'js/dom_types.ts')
-rw-r--r-- | js/dom_types.ts | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/js/dom_types.ts b/js/dom_types.ts index 75f683be5..3435825b1 100644 --- a/js/dom_types.ts +++ b/js/dom_types.ts @@ -13,7 +13,10 @@ See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. *******************************************************************************/ -export type HeadersInit = Headers | string[][] | Record<string, string>; +export type HeadersInit = + | Headers + | Array<[string, string]> + | Record<string, string>; export type URLSearchParamsInit = string | string[][] | Record<string, string>; type BodyInit = | Blob @@ -36,6 +39,18 @@ export type EventListenerOrEventListenerObject = | EventListener | EventListenerObject; +export interface DomIterable<K, V> { + keys(): IterableIterator<K>; + values(): IterableIterator<V>; + entries(): IterableIterator<[K, V]>; + [Symbol.iterator](): IterableIterator<[K, V]>; + forEach( + callback: (value: V, key: K, parent: this) => void, + // tslint:disable-next-line:no-any + thisArg?: any + ): void; +} + interface Element { // TODO } @@ -289,7 +304,7 @@ interface Body { text(): Promise<string>; } -export interface Headers { +export 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. */ @@ -322,7 +337,7 @@ export interface Headers { */ values(): IterableIterator<string>; forEach( - callbackfn: (value: string, key: string, parent: Headers) => void, + callbackfn: (value: string, key: string, parent: this) => void, // tslint:disable-next-line:no-any thisArg?: any ): void; @@ -332,6 +347,11 @@ export interface Headers { [Symbol.iterator](): IterableIterator<[string, string]>; } +export interface HeadersConstructor { + new (init?: HeadersInit): Headers; + prototype: Headers; +} + type RequestCache = | "default" | "no-store" |