diff --git a/whatwg-fetch/index.d.ts b/whatwg-fetch/index.d.ts deleted file mode 100644 index 67bde53016..0000000000 --- a/whatwg-fetch/index.d.ts +++ /dev/null @@ -1,115 +0,0 @@ -// Type definitions for Fetch API -// Project: https://github.com/github/fetch -// Definitions by: Ryan Graham , Kagami Sascha Rosylight -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - -/// - -interface Window { - fetch(input: RequestInfo, init?: RequestInit): Promise; -} -declare let fetch: typeof window.fetch; - -declare type HeadersInit = Headers | string[][] | { [key: string]: string }; -declare class Headers { - constructor(init?: HeadersInit); - - append(name: string, value: string): void; - delete(name: string): void; - get(name: string): string | null; - has(name: string): boolean; - set(name: string, value: string): void; - - // WebIDL pair iterator: iterable - entries(): IterableIterator<[string, string]>; - forEach(callback: (value: string, index: number, headers: Headers) => void, thisArg?: any): void; - keys(): IterableIterator; - values(): IterableIterator; - [Symbol.iterator](): IterableIterator<[string, string]>; -} - -declare type BodyInit = Blob | ArrayBufferView | ArrayBuffer | FormData /* | URLSearchParams */ | string; -declare type ResponseBodyInit = BodyInit | ReadableStream; -interface Body { - readonly bodyUsed: boolean; - arrayBuffer(): Promise; - blob(): Promise; - formData(): Promise; - json(): Promise; - json(): Promise; - text(): Promise; -} - -declare type RequestInfo = Request | string; -declare class Request { - constructor(input: RequestInfo, init?: RequestInit); - - readonly method: string; - readonly url: string; - readonly headers: Headers; - - readonly type: RequestType - readonly destination: RequestDestination; - readonly referrer: string; - readonly referrerPolicy: ReferrerPolicy; - readonly mode: RequestMode; - readonly credentials: RequestCredentials; - readonly cache: RequestCache; - readonly redirect: RequestRedirect; - readonly integrity: string; - readonly keepalive: boolean; - - clone(): Request; -} -interface Request extends Body {} -interface RequestInit { - method?: string; - headers?: HeadersInit; - body?: BodyInit; - referrer?: string; - referrerPolicy?: ReferrerPolicy; - mode?: RequestMode; - credentials?: RequestCredentials; - cache?: RequestCache; - redirect?: RequestRedirect; - integrity?: string; - window?: null; // can only be set to null -} - -type RequestType = "" | "audio" | "font" | "image" | "script" | "style" | "track" | "video"; -type RequestDestination = "" | "document" | "embed" | "font" | "image" | "manifest" | "media" | "object" | "report" | "script" | "serviceworker" | "sharedworker" | "style" | "worker" | "xslt"; -type RequestMode = "navigate" | "same-origin" | "no-cors" | "cors"; -type RequestCredentials = "omit" | "same-origin" | "include"; -type RequestCache = "default" | "no-store" | "reload" | "no-cache" | "force-cache" | "only-if-cached"; -type RequestRedirect = "follow" | "error" | "manual"; - -type ReferrerPolicy = "" | "no-referrer" | "no-referrer-when-downgrade" | "same-origin" | "origin" | "strict-origin" | "origin-when-cross-origin" | "strict-origin-when-cross-origin" | "unsafe-url"; - -declare class Response { - constructor(body?: ResponseBodyInit, init?: ResponseInit); - - static error(): Response; - static redirect(url: string, status?: number): Response; - - readonly type: ResponseType; - - readonly url: string; - readonly redirected: boolean; - readonly status: number; - readonly ok: boolean; - readonly statusText: string; - readonly headers: Headers; - readonly body: ReadableStream | null; - readonly trailer: Promise; - - clone(): Response; -} -interface Response extends Body {} - -interface ResponseInit { - status?: number; - statusText?: string; - headers?: HeadersInit; -} - -type ResponseType = "basic" | "cors" | "default" | "error" | "opaque" | "opaqueredirect"; diff --git a/whatwg-fetch/tsconfig.json b/whatwg-fetch/tsconfig.json deleted file mode 100644 index 1855761487..0000000000 --- a/whatwg-fetch/tsconfig.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "compilerOptions": { - "module": "commonjs", - "lib": [ - "es6", - "dom" - ], - "noImplicitAny": true, - "noImplicitThis": true, - "strictNullChecks": true, - "baseUrl": "../", - "typeRoots": [ - "../" - ], - "types": [], - "noEmit": true, - "forceConsistentCasingInFileNames": true - }, - "files": [ - "index.d.ts", - "whatwg-fetch-tests.ts" - ] -} \ No newline at end of file diff --git a/whatwg-fetch/whatwg-fetch-tests.ts b/whatwg-fetch/whatwg-fetch-tests.ts deleted file mode 100644 index 6c5e509749..0000000000 --- a/whatwg-fetch/whatwg-fetch-tests.ts +++ /dev/null @@ -1,110 +0,0 @@ - - -function test_HeadersCopiedFromHeaders() { - var source = new Headers(); - source.append('Content-Type', 'application/json'); - return new Headers(source); -} - -function test_HeadersCopiedFromHash() { - var source: DOMStringMap = { - 'Content-Type': 'application/json' - }; - return new Headers(source); -} - -function test_fetchUrlWithOptions() { - var headers = new Headers(); - headers.append("Content-Type", "application/json"); - var requestOptions: RequestInit = { - method: "POST", - headers: headers, - mode: 'same-origin', - credentials: 'omit', - cache: 'default', - redirect: 'manual' - }; - handlePromise(window.fetch("http://www.andlabs.net/html5/uCOR.php", requestOptions)); -} - -function test_fetchUrlWithHeadersObject() { - var requestOptions: RequestInit = { - method: "POST", - headers: { - 'Content-Type': 'application/json' - } - }; - handlePromise(window.fetch("http://www.andlabs.net/html5/uCOR.php", requestOptions)); -} - -function test_fetchUrl() { - handlePromise(window.fetch("http://www.andlabs.net/html5/uCOR.php")); -} - -function test_fetchUrlWithRequestObject() { - var requestOptions: RequestInit = { - method: "POST", - headers: { - 'Content-Type': 'application/json' - } - }; - var request: Request = new Request("http://www.andlabs.net/html5/uCOR.php", requestOptions); - handlePromise(window.fetch(request)); -} - -function test_globalFetchVar() { - fetch('http://test.com', {}) - .then(response => { - // for test only - }); -} - -function handlePromise(promise: Promise) { - promise.then((response) => { - if (response.type === 'basic') { - // for test only - } - return response.text(); - }).then((text) => { - console.log(text); - }); -} - -function test_Body_json() { - interface FooBar { - foo: string; - bar: string; - } - - fetch('http://test.com') - .then(response => response.json()) - .then(fooBar => { - console.log(fooBar.foo); - console.log(fooBar.bar); - }); - - fetch('http://test.com') - .then(response => > response.json()) - .then(fooBar => { - console.log(fooBar.foo); - console.log(fooBar.bar); - }); - - fetch('http://test.com') - .then(response => response.json() as Promise) - .then(fooBar => { - console.log(fooBar.foo); - console.log(fooBar.bar); - }); - - fetch('http://test.com') - .then(response => response.json()) - .then(fooBar => { - // fooBar is of type any, not of type FooBar - - // FIXME Was behaving properly with TypeScript 2.0.10, not anymore with 2.1.4 - // See Wrong type with Promise chaining and 2.1.4 https://github.com/Microsoft/TypeScript/issues/12409 - //console.log(fooBar.foo); - //console.log(fooBar.bar); - }); -}