import { URL } from 'url' import { Blob } from 'buffer' import { ReadableStream } from 'stream/web' import { expectType, expectError, expectAssignable, expectNotAssignable } from 'tsd' import { Agent, BodyInit, fetch, FormData, Headers, HeadersInit, SpecIterableIterator, Request, RequestCache, RequestCredentials, RequestDestination, RequestInit, RequestMode, RequestRedirect, Response, ResponseInit, ResponseType, ReferrerPolicy } from '../..' const requestInit: RequestInit = {} const responseInit: ResponseInit = { status: 200, statusText: 'OK' } const requestInit2: RequestInit = { dispatcher: new Agent() } const requestInit3: RequestInit = {} // Test assignment. See https://github.com/whatwg/fetch/issues/1445 requestInit3.credentials = 'include' declare const request: Request declare const headers: Headers declare const response: Response expectType(requestInit.method) expectType(requestInit.keepalive) expectType(requestInit.headers) expectType(requestInit.body) expectType(requestInit.redirect) expectType(requestInit.integrity) expectType(requestInit.signal) expectType(requestInit.credentials) expectType(requestInit.mode) expectType(requestInit.referrer); expectType(requestInit.referrerPolicy) expectType(requestInit.window) expectType(responseInit.status) expectType(responseInit.statusText) expectType(responseInit.headers) expectType(new Headers()) expectType(new Headers({})) expectType(new Headers([])) expectType(new Headers(headers)) expectType(new Headers(undefined)) expectType(new Request(request)) expectType(new Request('https://example.com')) expectType(new Request(new URL('https://example.com'))) expectType(new Request(request, requestInit)) expectType(new Request('https://example.com', requestInit)) expectType(new Request(new URL('https://example.com'), requestInit)) expectType>(fetch(request)) expectType>(fetch('https://example.com')) expectType>(fetch(new URL('https://example.com'))) expectType>(fetch(request, requestInit)) expectType>(fetch('https://example.com', requestInit)) expectType>(fetch(new URL('https://example.com'), requestInit)) expectType(new Response()) expectType(new Response(null)) expectType(new Response('string')) expectType(new Response(new Blob([]))) expectType(new Response(new FormData())) expectType(new Response(new Int8Array())) expectType(new Response(new Uint8Array())) expectType(new Response(new Uint8ClampedArray())) expectType(new Response(new Int16Array())) expectType(new Response(new Uint16Array())) expectType(new Response(new Int32Array())) expectType(new Response(new Uint32Array())) expectType(new Response(new Float32Array())) expectType(new Response(new Float64Array())) expectType(new Response(new BigInt64Array())) expectType(new Response(new BigUint64Array())) expectType(new Response(new ArrayBuffer(0))) expectType(new Response(null, responseInit)) expectType(new Response('string', responseInit)) expectType(new Response(new Blob([]), responseInit)) expectType(new Response(new FormData(), responseInit)) expectType(new Response(new Int8Array(), responseInit)) expectType(new Response(new Uint8Array(), responseInit)) expectType(new Response(new Uint8ClampedArray(), responseInit)) expectType(new Response(new Int16Array(), responseInit)) expectType(new Response(new Uint16Array(), responseInit)) expectType(new Response(new Int32Array(), responseInit)) expectType(new Response(new Uint32Array(), responseInit)) expectType(new Response(new Float32Array(), responseInit)) expectType(new Response(new Float64Array(), responseInit)) expectType(new Response(new BigInt64Array(), responseInit)) expectType(new Response(new BigUint64Array(), responseInit)) expectType(new Response(new ArrayBuffer(0), responseInit)) expectType(Response.error()) expectType(Response.json({ a: 'b' })) expectType(Response.json({}, { status: 200 })) expectType(Response.json({}, { statusText: 'OK' })) expectType(Response.json({}, { headers: {} })) expectType(Response.json(null)) expectType(Response.redirect('https://example.com', 301)) expectType(Response.redirect('https://example.com', 302)) expectType(Response.redirect('https://example.com', 303)) expectType(Response.redirect('https://example.com', 307)) expectType(Response.redirect('https://example.com', 308)) expectError(Response.redirect('https://example.com', NaN)) expectError(Response.json()) expectError(Response.json(null, 3)) expectType(headers.append('key', 'value')) expectType(headers.delete('key')) expectType(headers.get('key')) expectType(headers.has('key')) expectType(headers.set('key', 'value')) expectType>(headers.keys()) expectType>(headers.values()) expectType>(headers.entries()) expectType(request.cache) expectType(request.credentials) expectType(request.destination) expectType(request.headers) expectType(request.integrity) expectType(request.method) expectType(request.mode) expectType(request.redirect) expectType(request.referrerPolicy) expectType(request.url) expectType(request.keepalive) expectType(request.signal) expectType(request.bodyUsed) expectType>(request.arrayBuffer()) expectType>(request.blob()) expectType>(request.formData()) expectType>(request.json()) expectType>(request.text()) expectType(request.clone()) expectType(response.headers) expectType(response.ok) expectType(response.status) expectType(response.statusText) expectType(response.type) expectType(response.url) expectType(response.redirected) expectType(response.body) expectType(response.bodyUsed) expectType>(response.arrayBuffer()) expectType>(response.blob()) expectType>(response.formData()) expectType>(response.json()) expectType>(response.text()) expectType(response.clone()) expectType(new Request('https://example.com', { body: 'Hello, world', duplex: 'half' })) expectAssignable({ duplex: 'half' }) expectNotAssignable({ duplex: 'not valid' }) expectType(headers.getSetCookie())