Skip to content

Commit 10a4ec7

Browse files
authoredApr 22, 2024··
Fix request types for use with Node.js (#578)
1 parent 7760a81 commit 10a4ec7

File tree

1 file changed

+47
-6
lines changed

1 file changed

+47
-6
lines changed
 

‎source/types/request.ts

+47-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,56 @@
1+
/*
2+
Undici types need to be here because they are not exported to globals by @types/node.
3+
See https://github.com/DefinitelyTyped/DefinitelyTyped/discussions/69408
4+
5+
After the types are exported to globals, the Undici types can be removed from here.
6+
*/
7+
8+
type UndiciHeadersInit =
9+
| string[][]
10+
| Record<string, string | readonly string[]>
11+
| Headers;
12+
13+
type UndiciBodyInit =
14+
| ArrayBuffer
15+
| AsyncIterable<Uint8Array>
16+
| Blob
17+
| FormData
18+
| Iterable<Uint8Array>
19+
| NodeJS.ArrayBufferView
20+
| URLSearchParams
21+
// eslint-disable-next-line @typescript-eslint/ban-types
22+
| null
23+
| string;
24+
25+
type UndiciRequestRedirect = 'error' | 'follow' | 'manual';
26+
27+
type UndiciRequestCredentials = 'omit' | 'include' | 'same-origin';
28+
29+
type UndiciReferrerPolicy =
30+
| ''
31+
| 'no-referrer'
32+
| 'no-referrer-when-downgrade'
33+
| 'origin'
34+
| 'origin-when-cross-origin'
35+
| 'same-origin'
36+
| 'strict-origin'
37+
| 'strict-origin-when-cross-origin'
38+
| 'unsafe-url';
39+
40+
type UndiciRequestMode = 'cors' | 'navigate' | 'no-cors' | 'same-origin';
41+
142
type UndiciRequestInit = {
243
method?: string;
344
keepalive?: boolean;
4-
headers?: HeadersInit;
5-
body?: BodyInit;
6-
redirect?: RequestRedirect;
45+
headers?: UndiciHeadersInit;
46+
body?: UndiciBodyInit;
47+
redirect?: UndiciRequestRedirect;
748
integrity?: string;
849
signal?: AbortSignal | undefined;
9-
credentials?: RequestCredentials;
10-
mode?: RequestMode;
50+
credentials?: UndiciRequestCredentials;
51+
mode?: UndiciRequestMode;
1152
referrer?: string;
12-
referrerPolicy?: ReferrerPolicy;
53+
referrerPolicy?: UndiciReferrerPolicy;
1354
window?: undefined;
1455
dispatcher?: unknown;
1556
duplex?: unknown;

0 commit comments

Comments
 (0)
Please sign in to comment.