|
| 1 | +import { URL } from 'url' |
| 2 | +import { Blob } from 'buffer' |
| 3 | +import { expectType, expectError } from 'tsd' |
| 4 | +import { |
| 5 | + BodyInit, |
| 6 | + fetch, |
| 7 | + FormData, |
| 8 | + Headers, |
| 9 | + HeadersInit, |
| 10 | + Request, |
| 11 | + RequestCache, |
| 12 | + RequestCredentials, |
| 13 | + RequestDestination, |
| 14 | + RequestInit, |
| 15 | + RequestMode, |
| 16 | + RequestRedirect, |
| 17 | + Response, |
| 18 | + ResponseInit, |
| 19 | + ResponseType, |
| 20 | +} from '../..' |
| 21 | + |
| 22 | +const requestInit: RequestInit = {} |
| 23 | +const responseInit: ResponseInit = { status: 200, statusText: 'OK' } |
| 24 | + |
| 25 | +declare const request: Request |
| 26 | +declare const headers: Headers |
| 27 | +declare const response: Response |
| 28 | + |
| 29 | +expectType<string | undefined>(requestInit.method) |
| 30 | +expectType<boolean | undefined>(requestInit.keepalive) |
| 31 | +expectType<HeadersInit | undefined>(requestInit.headers) |
| 32 | +expectType<BodyInit | undefined>(requestInit.body) |
| 33 | +expectType<RequestRedirect | undefined>(requestInit.redirect) |
| 34 | +expectType<string | undefined>(requestInit.integrity) |
| 35 | +expectType<AbortSignal | undefined>(requestInit.signal) |
| 36 | + |
| 37 | +expectType<number | undefined>(responseInit.status) |
| 38 | +expectType<string | undefined>(responseInit.statusText) |
| 39 | +expectType<HeadersInit | undefined>(responseInit.headers) |
| 40 | + |
| 41 | +expectType<Headers>(new Headers()) |
| 42 | +expectType<Headers>(new Headers({})) |
| 43 | +expectType<Headers>(new Headers([])) |
| 44 | +expectType<Headers>(new Headers(headers)) |
| 45 | +expectType<Headers>(new Headers(undefined)) |
| 46 | + |
| 47 | +expectType<Request>(new Request(request)) |
| 48 | +expectType<Request>(new Request('https://example.com')) |
| 49 | +expectType<Request>(new Request(new URL('https://example.com'))) |
| 50 | +expectType<Request>(new Request(request, requestInit)) |
| 51 | +expectType<Request>(new Request('https://example.com', requestInit)) |
| 52 | +expectType<Request>(new Request(new URL('https://example.com'), requestInit)) |
| 53 | + |
| 54 | +expectType<Promise<Response>>(fetch(request)) |
| 55 | +expectType<Promise<Response>>(fetch('https://example.com')) |
| 56 | +expectType<Promise<Response>>(fetch(new URL('https://example.com'))) |
| 57 | +expectType<Promise<Response>>(fetch(request, requestInit)) |
| 58 | +expectType<Promise<Response>>(fetch('https://example.com', requestInit)) |
| 59 | +expectType<Promise<Response>>(fetch(new URL('https://example.com'), requestInit)) |
| 60 | + |
| 61 | +expectType<Response>(new Response()) |
| 62 | +expectType<Response>(new Response(null)) |
| 63 | +expectType<Response>(new Response('string')) |
| 64 | +expectType<Response>(new Response(new Blob([]))) |
| 65 | +expectType<Response>(new Response(new FormData())) |
| 66 | +expectType<Response>(new Response(new Int8Array())) |
| 67 | +expectType<Response>(new Response(new Uint8Array())) |
| 68 | +expectType<Response>(new Response(new Uint8ClampedArray())) |
| 69 | +expectType<Response>(new Response(new Int16Array())) |
| 70 | +expectType<Response>(new Response(new Uint16Array())) |
| 71 | +expectType<Response>(new Response(new Int32Array())) |
| 72 | +expectType<Response>(new Response(new Uint32Array())) |
| 73 | +expectType<Response>(new Response(new Float32Array())) |
| 74 | +expectType<Response>(new Response(new Float64Array())) |
| 75 | +expectType<Response>(new Response(new BigInt64Array())) |
| 76 | +expectType<Response>(new Response(new BigUint64Array())) |
| 77 | +expectType<Response>(new Response(new ArrayBuffer(0))) |
| 78 | +expectType<Response>(new Response(null, responseInit)) |
| 79 | +expectType<Response>(new Response('string', responseInit)) |
| 80 | +expectType<Response>(new Response(new Blob([]), responseInit)) |
| 81 | +expectType<Response>(new Response(new FormData(), responseInit)) |
| 82 | +expectType<Response>(new Response(new Int8Array(), responseInit)) |
| 83 | +expectType<Response>(new Response(new Uint8Array(), responseInit)) |
| 84 | +expectType<Response>(new Response(new Uint8ClampedArray(), responseInit)) |
| 85 | +expectType<Response>(new Response(new Int16Array(), responseInit)) |
| 86 | +expectType<Response>(new Response(new Uint16Array(), responseInit)) |
| 87 | +expectType<Response>(new Response(new Int32Array(), responseInit)) |
| 88 | +expectType<Response>(new Response(new Uint32Array(), responseInit)) |
| 89 | +expectType<Response>(new Response(new Float32Array(), responseInit)) |
| 90 | +expectType<Response>(new Response(new Float64Array(), responseInit)) |
| 91 | +expectType<Response>(new Response(new BigInt64Array(), responseInit)) |
| 92 | +expectType<Response>(new Response(new BigUint64Array(), responseInit)) |
| 93 | +expectType<Response>(new Response(new ArrayBuffer(0), responseInit)) |
| 94 | +expectType<Response>(Response.error()) |
| 95 | +expectType<Response>(Response.redirect('https://example.com', 301)) |
| 96 | +expectType<Response>(Response.redirect('https://example.com', 302)) |
| 97 | +expectType<Response>(Response.redirect('https://example.com', 303)) |
| 98 | +expectType<Response>(Response.redirect('https://example.com', 307)) |
| 99 | +expectType<Response>(Response.redirect('https://example.com', 308)) |
| 100 | +expectError(Response.redirect('https://example.com', NaN)) |
| 101 | + |
| 102 | +expectType<void>(headers.append('key', 'value')) |
| 103 | +expectType<void>(headers.delete('key')) |
| 104 | +expectType<string | null>(headers.get('key')) |
| 105 | +expectType<boolean>(headers.has('key')) |
| 106 | +expectType<void>(headers.set('key', 'value')) |
| 107 | +expectType<IterableIterator<string>>(headers.keys()) |
| 108 | +expectType<IterableIterator<string>>(headers.values()) |
| 109 | +expectType<IterableIterator<[string, string]>>(headers.entries()) |
| 110 | + |
| 111 | +expectType<RequestCache>(request.cache) |
| 112 | +expectType<RequestCredentials>(request.credentials) |
| 113 | +expectType<RequestDestination>(request.destination) |
| 114 | +expectType<Headers>(request.headers) |
| 115 | +expectType<string>(request.integrity) |
| 116 | +expectType<string>(request.method) |
| 117 | +expectType<RequestMode>(request.mode) |
| 118 | +expectType<RequestRedirect>(request.redirect) |
| 119 | +expectType<string>(request.referrerPolicy) |
| 120 | +expectType<string>(request.url) |
| 121 | +expectType<boolean>(request.keepalive) |
| 122 | +expectType<AbortSignal>(request.signal) |
| 123 | +expectType<boolean>(request.bodyUsed) |
| 124 | +expectType<Promise<Buffer>>(request.arrayBuffer()) |
| 125 | +expectType<Promise<Blob>>(request.blob()) |
| 126 | +expectType<Promise<FormData>>(request.formData()) |
| 127 | +expectType<Promise<unknown>>(request.json()) |
| 128 | +expectType<Promise<string>>(request.text()) |
| 129 | +expectType<Request>(request.clone()) |
| 130 | + |
| 131 | +expectType<Headers>(response.headers) |
| 132 | +expectType<boolean>(response.ok) |
| 133 | +expectType<number>(response.status) |
| 134 | +expectType<string>(response.statusText) |
| 135 | +expectType<ResponseType>(response.type) |
| 136 | +expectType<string>(response.url) |
| 137 | +expectType<boolean>(response.redirected) |
| 138 | +expectType<boolean>(response.bodyUsed) |
| 139 | +expectType<Promise<Buffer>>(response.arrayBuffer()) |
| 140 | +expectType<Promise<Blob>>(response.blob()) |
| 141 | +expectType<Promise<FormData>>(response.formData()) |
| 142 | +expectType<Promise<unknown>>(response.json()) |
| 143 | +expectType<Promise<string>>(response.text()) |
| 144 | +expectType<Response>(response.clone()) |
0 commit comments