Skip to content

Commit a6664b9

Browse files
fix: TypeScript declaration for Headers (#1155)
1 parent 4047c7b commit a6664b9

File tree

3 files changed

+53
-11
lines changed

3 files changed

+53
-11
lines changed

integration-tests/js-compute/fixtures/app/src/headers.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,20 @@ routes.set('/headers/non-ascii-latin1-field-value', async () => {
2121
assert(text, 'é', `response.headers.get('cat') === "é"`);
2222
});
2323

24+
routes.set('/headers/getsetcookie', async () => {
25+
let response = await fetch(
26+
'https://http-me.glitch.me/meow?header=Set-Cookie:name1=value1',
27+
{
28+
backend: 'httpme',
29+
},
30+
);
31+
response.headers.append('Set-Cookie', 'name2=value2');
32+
console.log(
33+
'response.headers.getSetCookie()',
34+
response.headers.getSetCookie(),
35+
);
36+
});
37+
2438
routes.set('/headers/from-response/set', async () => {
2539
const response = await fetch('https://httpbin.org/stream-bytes/11', {
2640
backend: 'httpbin',

integration-tests/js-compute/fixtures/app/tests.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,6 +1358,12 @@
13581358
"body": "ok"
13591359
}
13601360
},
1361+
"GET /headers/getsetcookie": {
1362+
"downstream_response": {
1363+
"status": 200,
1364+
"headers": [["name1=value1"], ["name2=value2"]]
1365+
}
1366+
},
13611367
"GET /headers/construct": {
13621368
"downstream_response": {
13631369
"status": 200,

types/globals.d.ts

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,7 +1148,7 @@ and limitations under the License.
11481148
*/
11491149

11501150
type BlobPart = BufferSource | Blob | string;
1151-
type EndingType = "native" | "transparent";
1151+
type EndingType = 'native' | 'transparent';
11521152
type FormDataEntryValue = File | string;
11531153

11541154
interface BlobPropertyBag {
@@ -1182,7 +1182,7 @@ interface Blob {
11821182

11831183
declare var Blob: {
11841184
prototype: Blob;
1185-
new(blobParts?: BlobPart[], options?: BlobPropertyBag): Blob;
1185+
new (blobParts?: BlobPart[], options?: BlobPropertyBag): Blob;
11861186
};
11871187

11881188
/**
@@ -1201,7 +1201,7 @@ interface File extends Blob {
12011201

12021202
declare var File: {
12031203
prototype: File;
1204-
new(fileBits: BlobPart[], fileName: string, options?: FilePropertyBag): File;
1204+
new (fileBits: BlobPart[], fileName: string, options?: FilePropertyBag): File;
12051205
};
12061206

12071207
/**
@@ -1226,12 +1226,21 @@ interface FormData {
12261226
set(name: string, value: string | Blob): void;
12271227
set(name: string, value: string): void;
12281228
set(name: string, blobValue: Blob, filename?: string): void;
1229-
forEach(callbackfn: (value: FormDataEntryValue, key: string, parent: FormData) => void, thisArg?: any): void;
1229+
forEach(
1230+
callbackfn: (
1231+
value: FormDataEntryValue,
1232+
key: string,
1233+
parent: FormData,
1234+
) => void,
1235+
thisArg?: any,
1236+
): void;
12301237
}
12311238

12321239
declare var FormData: {
12331240
prototype: FormData;
1234-
new(form?: any/*form?: HTMLFormElement, submitter?: HTMLElement | null*/): FormData;
1241+
new (
1242+
form?: any /*form?: HTMLFormElement, submitter?: HTMLElement | null*/,
1243+
): FormData;
12351244
};
12361245

12371246
/**
@@ -1242,7 +1251,12 @@ declare var FormData: {
12421251
* @group Fetch API
12431252
*/
12441253
declare type BodyInit = ReadableStream | XMLHttpRequestBodyInit;
1245-
declare type XMLHttpRequestBodyInit = Blob | BufferSource | FormData | URLSearchParams | string;
1254+
declare type XMLHttpRequestBodyInit =
1255+
| Blob
1256+
| BufferSource
1257+
| FormData
1258+
| URLSearchParams
1259+
| string;
12461260

12471261
/**
12481262
* Body for Fetch HTTP Requests and Responses
@@ -1919,6 +1933,7 @@ interface Headers {
19191933
append(name: string, value: string): void;
19201934
delete(name: string): void;
19211935
get(name: string): string | null;
1936+
getSetCookie(): string[];
19221937
has(name: string): boolean;
19231938
set(name: string, value: string): void;
19241939
forEach(
@@ -2405,7 +2420,7 @@ interface Event {
24052420

24062421
declare var Event: {
24072422
prototype: Event;
2408-
new(type: string, eventInitDict?: EventInit): Event;
2423+
new (type: string, eventInitDict?: EventInit): Event;
24092424
readonly NONE: 0;
24102425
readonly CAPTURING_PHASE: 1;
24112426
readonly AT_TARGET: 2;
@@ -2444,7 +2459,11 @@ interface EventTarget {
24442459
*
24452460
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventTarget/addEventListener)
24462461
*/
2447-
addEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: AddEventListenerOptions | boolean): void;
2462+
addEventListener(
2463+
type: string,
2464+
callback: EventListenerOrEventListenerObject | null,
2465+
options?: AddEventListenerOptions | boolean,
2466+
): void;
24482467
/**
24492468
* Dispatches a synthetic event event to target and returns true if either event's cancelable attribute value is false or its preventDefault() method was not invoked, and false otherwise.
24502469
*
@@ -2456,15 +2475,18 @@ interface EventTarget {
24562475
*
24572476
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventTarget/removeEventListener)
24582477
*/
2459-
removeEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: EventListenerOptions | boolean): void;
2478+
removeEventListener(
2479+
type: string,
2480+
callback: EventListenerOrEventListenerObject | null,
2481+
options?: EventListenerOptions | boolean,
2482+
): void;
24602483
}
24612484

24622485
declare var EventTarget: {
24632486
prototype: EventTarget;
2464-
new(): EventTarget;
2487+
new (): EventTarget;
24652488
};
24662489

2467-
24682490
/**
24692491
* Provides access to performance-related information for the current page. It's part of the High Resolution Time API, but is enhanced by the Performance Timeline API, the Navigation Timing API, the User Timing API, and the Resource Timing API.
24702492
*

0 commit comments

Comments
 (0)