diff --git a/types/node-fetch/index.d.ts b/types/node-fetch/index.d.ts index d39b6db22e..aaaf30a5e3 100644 --- a/types/node-fetch/index.d.ts +++ b/types/node-fetch/index.d.ts @@ -77,6 +77,7 @@ export class Body { json(): Promise; text(): Promise; buffer(): Promise; + arrayBuffer(): Promise; } export class Response extends Body { diff --git a/types/node-fetch/node-fetch-tests.ts b/types/node-fetch/node-fetch-tests.ts index dbf140225f..564a31fe79 100644 --- a/types/node-fetch/node-fetch-tests.ts +++ b/types/node-fetch/node-fetch-tests.ts @@ -30,6 +30,10 @@ function test_fetchUrl() { handlePromise(fetch("http://www.andlabs.net/html5/uCOR.php")); } +function test_fetchUrlArrayBuffer() { + handlePromise(fetch("http://www.andlabs.net/html5/uCOR.php"), true); +} + function test_fetchUrlWithRequestObject() { var requestOptions: RequestInit = { method: "POST", @@ -53,13 +57,17 @@ function test_globalFetchVar() { }); } -function handlePromise(promise: Promise) { - promise.then((response) => { +function handlePromise(promise: Promise, isArrayBuffer: boolean = false) { + promise.then((response):Promise => { if (response.type === 'basic') { // for test only } - return response.text(); - }).then((text) => { + if (isArrayBuffer) { + return response.arrayBuffer(); + } else { + return response.text(); + } + }).then((text:string | ArrayBuffer) => { console.log(text); }); }