mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-16 19:09:18 +08:00
node-fetch: introduce namespace _fetch for tests
This commit is contained in:
@@ -3,9 +3,9 @@
|
||||
import fetch = require('node-fetch');
|
||||
|
||||
function test_fetchUrlWithOptions() {
|
||||
var headers = new Headers();
|
||||
var headers = new _fetch.Headers();
|
||||
headers.append("Content-Type", "application/json");
|
||||
var requestOptions: RequestInit = {
|
||||
var requestOptions: _fetch.RequestInit = {
|
||||
method: "POST",
|
||||
headers: headers,
|
||||
mode: 'same-origin',
|
||||
@@ -17,7 +17,7 @@ function test_fetchUrlWithOptions() {
|
||||
}
|
||||
|
||||
function test_fetchUrlWithHeadersObject() {
|
||||
var requestOptions: RequestInit = {
|
||||
var requestOptions: _fetch.RequestInit = {
|
||||
method: "POST",
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
@@ -31,13 +31,13 @@ function test_fetchUrl() {
|
||||
}
|
||||
|
||||
function test_fetchUrlWithRequestObject() {
|
||||
var requestOptions: RequestInit = {
|
||||
var requestOptions: _fetch.RequestInit = {
|
||||
method: "POST",
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
};
|
||||
var request: Request = new Request("http://www.andlabs.net/html5/uCOR.php", requestOptions);
|
||||
var request: _fetch.Request = new _fetch.Request("http://www.andlabs.net/html5/uCOR.php", requestOptions);
|
||||
handlePromise(fetch(request));
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ function test_globalFetchVar() {
|
||||
});
|
||||
}
|
||||
|
||||
function handlePromise(promise: Promise<Response>) {
|
||||
function handlePromise(promise: Promise<_fetch.Response>) {
|
||||
promise.then((response) => {
|
||||
if (response.type === 'basic') {
|
||||
// for test only
|
||||
|
||||
7
node-fetch/node-fetch.d.ts
vendored
7
node-fetch/node-fetch.d.ts
vendored
@@ -3,7 +3,7 @@
|
||||
// Definitions by: Torsten Werner <https://github.com/torstenwerner>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
declare module 'node-fetch' {
|
||||
declare module _fetch {
|
||||
|
||||
class Request extends Body {
|
||||
constructor(input: string | Request, init?: RequestInit);
|
||||
@@ -88,5 +88,8 @@ declare module 'node-fetch' {
|
||||
type RequestInfo = Request | string;
|
||||
|
||||
function fetch(url: string | Request, init?: RequestInit): Promise<Response>;
|
||||
export = fetch;
|
||||
}
|
||||
|
||||
declare module "node-fetch" {
|
||||
export = _fetch.fetch;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user