From 1d790808cacad2212e3e60080ba390b1b29bdc77 Mon Sep 17 00:00:00 2001 From: Jonathan Stewmon Date: Thu, 18 Mar 2021 15:30:10 -0500 Subject: [PATCH] add missing Headers interface augmentation from lib.dom.iterable.d.ts Added test.ts to support type checking the type declaration files. declaration files were generated and tested with the following command: npm i --no-save typescript@4.2.3 \ && cat < .ts-graftrc.yaml \ && npx ts-graft@1.0.1 \ && rm .ts-graftrc.yaml \ && npx tsc --lib ES2016 --target ES2016 --noEmit test.ts \ && npm un typescript grafts: - source: typescript/lib/lib.dom.d.ts output: lib.fetch.d.ts include: - BodyInit - HeadersInit - RequestInfo - RequestInit - Response - ResponseInit - source: typescript/lib/lib.dom.iterable.d.ts output: lib.fetch.dom.iterable.d.ts include: - Headers EOF --- index.d.ts | 6 ++++-- lib.fetch.dom.iterable.d.ts | 16 ++++++++++++++++ test.ts | 6 ++++++ 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 lib.fetch.dom.iterable.d.ts create mode 100644 test.ts diff --git a/index.d.ts b/index.d.ts index 0d1c548..d08c86f 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,6 +1,6 @@ -import { +import type { BodyInit, - Headers, + Headers as BaseHeaders, HeadersInit, Request, RequestInfo, @@ -8,6 +8,8 @@ import { Response, ResponseInit, } from "./lib.fetch" +import type { Headers as IterHeaders } from "./lib.fetch.dom.iterable"; +type Headers = BaseHeaders & IterHeaders; export const fetch: (input: RequestInfo, init?: RequestInit) => Promise; diff --git a/lib.fetch.dom.iterable.d.ts b/lib.fetch.dom.iterable.d.ts new file mode 100644 index 0000000..66639a0 --- /dev/null +++ b/lib.fetch.dom.iterable.d.ts @@ -0,0 +1,16 @@ +// Generated by resolving typescript/lib/lib.dom.iterable.d.ts from typescript@4.2.3 +export interface Headers { + [Symbol.iterator](): IterableIterator<[string, string]>; + /** + * Returns an iterator allowing to go through all key/value pairs contained in this object. + */ + entries(): IterableIterator<[string, string]>; + /** + * Returns an iterator allowing to go through all keys of the key/value pairs contained in this object. + */ + keys(): IterableIterator; + /** + * Returns an iterator allowing to go through all values of the key/value pairs contained in this object. + */ + values(): IterableIterator; +} diff --git a/test.ts b/test.ts new file mode 100644 index 0000000..39b5914 --- /dev/null +++ b/test.ts @@ -0,0 +1,6 @@ +import { Headers } from "./index"; + +const headers = new Headers(); +for (const h of headers) { + +}