From 4cb5f8c313ec0a2671735cb19a8faf8bfdf435ad Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Wed, 19 Apr 2017 13:11:17 -0700 Subject: [PATCH] isomorphic-fetch: Just use fetch `--lib dom`. --- types/isomorphic-fetch/index.d.ts | 116 +----------------- .../isomorphic-fetch-tests.ts | 38 +++--- types/isomorphic-fetch/tslint.json | 1 + 3 files changed, 23 insertions(+), 132 deletions(-) create mode 100644 types/isomorphic-fetch/tslint.json diff --git a/types/isomorphic-fetch/index.d.ts b/types/isomorphic-fetch/index.d.ts index 00b40fe911..7fbc0d8ed2 100644 --- a/types/isomorphic-fetch/index.d.ts +++ b/types/isomorphic-fetch/index.d.ts @@ -2,116 +2,8 @@ // Project: https://github.com/matthew-andrews/isomorphic-fetch // Definitions by: Todd Lucas // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 -interface ForEachCallback { - (keyId: any, status: string): void; -} - -interface Headers { - append(name: string, value: string): void; - delete(name: string): void; - forEach(callback: ForEachCallback): void; - get(name: string): string | null; - has(name: string): boolean; - set(name: string, value: string): void; -} - -declare var Headers: { - prototype: Headers; - new(init?: any): Headers; -} - -interface Blob { - readonly size: number; - readonly type: string; - msClose(): void; - msDetachStream(): any; - slice(start?: number, end?: number, contentType?: string): Blob; -} - -interface Body { - readonly bodyUsed: boolean; - arrayBuffer(): Promise; - blob(): Promise; - json(): Promise; - text(): Promise; -} - -interface RequestInit { - method?: string; - headers?: any; - body?: any; - referrer?: string; - referrerPolicy?: string; - mode?: string; - credentials?: string; - cache?: string; - redirect?: string; - integrity?: string; - keepalive?: boolean; - window?: any; -} - -interface Request extends Object, Body { - readonly cache: string; - readonly credentials: string; - readonly destination: string; - readonly headers: Headers; - readonly integrity: string; - readonly keepalive: boolean; - readonly method: string; - readonly mode: string; - readonly redirect: string; - readonly referrer: string; - readonly referrerPolicy: string; - readonly type: string; - readonly url: string; - clone(): Request; -} - -declare var Request: { - prototype: Request; - new(input: Request | string, init?: RequestInit): Request; -} - -interface ReadableStream { - readonly locked: boolean; - cancel(): Promise; -} - -interface ResponseInit { - status?: number; - statusText?: string; - headers?: any; -} - -interface Response extends Object, Body { - readonly body: ReadableStream | null; - readonly headers: Headers; - readonly ok: boolean; - readonly status: number; - readonly statusText: string; - readonly type: string; - readonly url: string; - clone(): Response; -} - -declare var Response: { - prototype: Response; - new(body?: any, init?: ResponseInit): Response; -} - -interface GlobalFetch { - fetch(input: Request | string, init?: RequestInit): Promise; -} - -interface Window extends GlobalFetch { -} - -declare function fetch(input: Request | string, init?: RequestInit): Promise; - -declare module "isomorphic-fetch" { - namespace _fetch { } - const _fetch: typeof fetch; - export = _fetch; -} +declare namespace _fetch { } +declare const _fetch: typeof fetch; +export = _fetch; diff --git a/types/isomorphic-fetch/isomorphic-fetch-tests.ts b/types/isomorphic-fetch/isomorphic-fetch-tests.ts index ac1a008350..6c5ad99a68 100644 --- a/types/isomorphic-fetch/isomorphic-fetch-tests.ts +++ b/types/isomorphic-fetch/isomorphic-fetch-tests.ts @@ -1,4 +1,3 @@ -/// import fetchImportedViaCommonJS = require('isomorphic-fetch'); import * as fetchImportedViaES6Module from 'isomorphic-fetch'; @@ -35,13 +34,12 @@ function test_isomorphicFetchTestCases_es6() { }); } - function test_whatwgTestCases_ambient() { - var headers = new Headers(); + const headers = new Headers(); headers.append("Content-Type", "application/json"); - var requestOptions: RequestInit = { + let requestOptions: RequestInit = { method: "POST", - headers: headers, + headers, mode: 'same-origin', credentials: 'omit', cache: 'default' @@ -49,7 +47,7 @@ function test_whatwgTestCases_ambient() { expectSuccess(fetch('http://localhost:3000/poster', requestOptions), 'Post response:'); - var requestOptions: RequestInit = { + requestOptions = { method: "POST", headers: { 'Content-Type': 'application/json' @@ -58,23 +56,23 @@ function test_whatwgTestCases_ambient() { expectSuccess(fetch('http://localhost:3000/poster', requestOptions), 'Post response:'); - var requestOptions: RequestInit = { + requestOptions = { method: "POST", headers: { 'Content-Type': 'application/json' } }; - var request: Request = new Request('http://localhost:3000/poster', requestOptions); + const request: Request = new Request('http://localhost:3000/poster', requestOptions); expectSuccess(fetch(request), 'Post response:'); } function test_whatwgTestCases_commonjs() { - var headers = new Headers(); + const headers = new Headers(); headers.append("Content-Type", "application/json"); - var requestOptions: RequestInit = { + let requestOptions: RequestInit = { method: "POST", - headers: headers, + headers, mode: 'same-origin', credentials: 'omit', cache: 'default' @@ -82,7 +80,7 @@ function test_whatwgTestCases_commonjs() { expectSuccess(fetchImportedViaCommonJS('http://localhost:3000/poster', requestOptions), 'Post response:'); - var requestOptions: RequestInit = { + requestOptions = { method: "POST", headers: { 'Content-Type': 'application/json' @@ -91,23 +89,23 @@ function test_whatwgTestCases_commonjs() { expectSuccess(fetchImportedViaCommonJS('http://localhost:3000/poster', requestOptions), 'Post response:'); - var requestOptions: RequestInit = { + requestOptions = { method: "POST", headers: { 'Content-Type': 'application/json' } }; - var request: Request = new Request('http://localhost:3000/poster', requestOptions); + const request: Request = new Request('http://localhost:3000/poster', requestOptions); expectSuccess(fetchImportedViaCommonJS(request), 'Post response:'); } function test_whatwgTestCases_es6() { - var headers = new Headers(); + const headers = new Headers(); headers.append("Content-Type", "application/json"); - var requestOptions: RequestInit = { + let requestOptions: RequestInit = { method: "POST", - headers: headers, + headers, mode: 'same-origin', credentials: 'omit', cache: 'default' @@ -115,7 +113,7 @@ function test_whatwgTestCases_es6() { expectSuccess(fetchImportedViaES6Module('http://localhost:3000/poster', requestOptions), 'Post response:'); - var requestOptions: RequestInit = { + requestOptions = { method: "POST", headers: { 'Content-Type': 'application/json' @@ -124,13 +122,13 @@ function test_whatwgTestCases_es6() { expectSuccess(fetchImportedViaES6Module('http://localhost:3000/poster', requestOptions), 'Post response:'); - var requestOptions: RequestInit = { + requestOptions = { method: "POST", headers: { 'Content-Type': 'application/json' } }; - var request: Request = new Request('http://localhost:3000/poster', requestOptions); + const request: Request = new Request('http://localhost:3000/poster', requestOptions); expectSuccess(fetchImportedViaES6Module(request), 'Post response:'); } diff --git a/types/isomorphic-fetch/tslint.json b/types/isomorphic-fetch/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/isomorphic-fetch/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }