Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix request types for use with Node #578

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 47 additions & 6 deletions source/types/request.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,56 @@
/*
Undici types need to be here because they are not exported to globals by @types/node.
See https://github.com/DefinitelyTyped/DefinitelyTyped/discussions/69408

After the types are exported to globals, the Undici types can be removed from here.
*/

type UndiciHeadersInit =
| string[][]
| Record<string, string | readonly string[]>
| Headers;

type UndiciBodyInit =
| ArrayBuffer
| AsyncIterable<Uint8Array>
| Blob
| FormData
| Iterable<Uint8Array>
| NodeJS.ArrayBufferView
| URLSearchParams
// eslint-disable-next-line @typescript-eslint/ban-types
| null
| string;

type UndiciRequestRedirect = 'error' | 'follow' | 'manual';

type UndiciRequestCredentials = 'omit' | 'include' | 'same-origin';

type UndiciReferrerPolicy =
| ''
| 'no-referrer'
| 'no-referrer-when-downgrade'
| 'origin'
| 'origin-when-cross-origin'
| 'same-origin'
| 'strict-origin'
| 'strict-origin-when-cross-origin'
| 'unsafe-url';

type UndiciRequestMode = 'cors' | 'navigate' | 'no-cors' | 'same-origin';

type UndiciRequestInit = {
method?: string;
keepalive?: boolean;
headers?: HeadersInit;
body?: BodyInit;
redirect?: RequestRedirect;
headers?: UndiciHeadersInit;
body?: UndiciBodyInit;
redirect?: UndiciRequestRedirect;
integrity?: string;
signal?: AbortSignal | undefined;
credentials?: RequestCredentials;
mode?: RequestMode;
credentials?: UndiciRequestCredentials;
mode?: UndiciRequestMode;
referrer?: string;
referrerPolicy?: ReferrerPolicy;
referrerPolicy?: UndiciReferrerPolicy;
window?: undefined;
dispatcher?: unknown;
duplex?: unknown;
Expand Down