mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-12 04:50:18 +00:00
Add RequestInit.signal to node-fetch (#35636)
* Add RequestInit.signal to node-fetch * Make comments more clear. Co-Authored-By: Niklas Lindgren <nikc@iki.fi> * Move AbortSignal into its own file * rename to externals.d.ts per suggestion * Make more requested changes * add back files entry, as required by checks * Add back import/export
This commit is contained in:
committed by
Andrew Casey
co-authored by
Niklas Lindgren
parent
1e006bf325
commit
879861b8ee
Vendored
+21
@@ -0,0 +1,21 @@
|
||||
// `AbortSignal` is defined here to prevent a dependency on a particular
|
||||
// implementation like the `abort-controller` package, and to avoid requiring
|
||||
// the `dom` library in `tsconfig.json`.
|
||||
|
||||
export interface AbortSignal {
|
||||
aborted: boolean;
|
||||
|
||||
addEventListener: (type: "abort", listener: ((this: AbortSignal, event: any) => any), options?: boolean | {
|
||||
capture?: boolean,
|
||||
once?: boolean,
|
||||
passive?: boolean
|
||||
}) => void;
|
||||
|
||||
removeEventListener: (type: "abort", listener: ((this: AbortSignal, event: any) => any), options?: boolean | {
|
||||
capture?: boolean
|
||||
}) => void;
|
||||
|
||||
dispatchEvent: (event: any) => boolean;
|
||||
|
||||
onabort?: null | ((this: AbortSignal, event: any) => void);
|
||||
}
|
||||
Vendored
+2
@@ -13,6 +13,7 @@
|
||||
|
||||
import { Agent } from "http";
|
||||
import { URLSearchParams } from "url";
|
||||
import { AbortSignal } from "./externals";
|
||||
|
||||
export class Request extends Body {
|
||||
constructor(input: string | { href: string } | Request, init?: RequestInit);
|
||||
@@ -42,6 +43,7 @@ export interface RequestInit {
|
||||
headers?: HeadersInit;
|
||||
method?: string;
|
||||
redirect?: RequestRedirect;
|
||||
signal?: AbortSignal | null;
|
||||
|
||||
// node-fetch extensions
|
||||
agent?: Agent; // =null http.Agent instance, allows custom proxy, certificate etc.
|
||||
|
||||
@@ -50,6 +50,21 @@ function test_fetchUrlWithRequestObject() {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
signal: {
|
||||
aborted: false,
|
||||
|
||||
addEventListener: (type: "abort", listener: ((event: any) => any), options?: boolean | {
|
||||
capture?: boolean,
|
||||
once?: boolean,
|
||||
passive?: boolean
|
||||
}) => undefined,
|
||||
|
||||
removeEventListener: (type: "abort", listener: ((event: any) => any), options?: boolean | {
|
||||
capture?: boolean
|
||||
}) => undefined,
|
||||
|
||||
dispatchEvent: (event: any) => false
|
||||
}
|
||||
};
|
||||
const request: Request = new Request(
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"externals.d.ts",
|
||||
"node-fetch-tests.ts"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user