From aee338f484683fdd3902a6cd909b040ec99661b9 Mon Sep 17 00:00:00 2001 From: Oliver Joseph Ash Date: Sat, 21 Jul 2018 02:01:15 +0100 Subject: [PATCH] `node-fetch`: correct `Headers.raw` type (#27364) * `node-fetch`: add test for `Headers.raw` * `node-fetch`: `Headers.raw`: add `string[]` to index signature value type * `node-fetch`: `Headers.raw`: add `undefined` to index signature value type * `node-fetch`: enable `strictNullChecks` and fix errors * Revert "`node-fetch`: `Headers.raw`: add `undefined` to index signature value type" This reverts commit 15ad14d72c42fa1f3ba472bc15f38a88230f3a4f. * Fix expect type format * Remove string --- types/node-fetch/index.d.ts | 2 +- types/node-fetch/node-fetch-tests.ts | 8 +++++++- types/node-fetch/tsconfig.json | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/types/node-fetch/index.d.ts b/types/node-fetch/index.d.ts index b203744a72..4b12734363 100644 --- a/types/node-fetch/index.d.ts +++ b/types/node-fetch/index.d.ts @@ -102,7 +102,7 @@ export class Headers implements Iterable<[string, string]> { get(name: string): string | null; getAll(name: string): string[]; has(name: string): boolean; - raw(): { [k: string]: string }; + raw(): { [k: string]: string[] }; set(name: string, value: string): void; // Iterator methods diff --git a/types/node-fetch/node-fetch-tests.ts b/types/node-fetch/node-fetch-tests.ts index 6f78a512cf..7561ae1b0f 100644 --- a/types/node-fetch/node-fetch-tests.ts +++ b/types/node-fetch/node-fetch-tests.ts @@ -44,7 +44,7 @@ function test_fetchUrlWithRequestObject() { const request: Request = new Request("http://www.andlabs.net/html5/uCOR.php", requestOptions); const timeout: number = request.timeout; const size: number = request.size; - const agent: Agent = request.agent; + const agent: Agent | undefined = request.agent; const protocol: string = request.protocol; handlePromise(fetch(request)); @@ -71,3 +71,9 @@ function handlePromise(promise: Promise, isArrayBuffer: boolean = fals console.log(text); }); } + +function test_headersRaw() { + const headers = new Headers(); + const myHeader = 'foo'; + headers.raw()[myHeader]; // $ExpectType string[] +} diff --git a/types/node-fetch/tsconfig.json b/types/node-fetch/tsconfig.json index 98a8d56ff1..d349bf9665 100644 --- a/types/node-fetch/tsconfig.json +++ b/types/node-fetch/tsconfig.json @@ -7,7 +7,7 @@ ], "noImplicitAny": true, "noImplicitThis": true, - "strictNullChecks": false, + "strictNullChecks": true, "strictFunctionTypes": true, "baseUrl": "../", "typeRoots": [