Skip to content

Commit

Permalink
add missing Headers interface augmentation from lib.dom.iterable.d.ts
Browse files Browse the repository at this point in the history
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 <<EOF > .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
  • Loading branch information
jstewmon committed Mar 18, 2021
1 parent 633fa8c commit 1d79080
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
6 changes: 4 additions & 2 deletions index.d.ts
@@ -1,13 +1,15 @@
import {
import type {
BodyInit,
Headers,
Headers as BaseHeaders,
HeadersInit,
Request,
RequestInfo,
RequestInit,
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<Response>;

Expand Down
16 changes: 16 additions & 0 deletions 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<string>;
/**
* Returns an iterator allowing to go through all values of the key/value pairs contained in this object.
*/
values(): IterableIterator<string>;
}
6 changes: 6 additions & 0 deletions test.ts
@@ -0,0 +1,6 @@
import { Headers } from "./index";

const headers = new Headers();
for (const h of headers) {

}

0 comments on commit 1d79080

Please sign in to comment.