Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions test/types/fetch.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import {
ResponseInit,
ResponseType,
ReferrerPolicy,
Dispatcher
Dispatcher,
HttpMethod
} from '../..'

const requestInit: RequestInit = {}
Expand All @@ -33,6 +34,12 @@ const requestInit3: RequestInit = {}
// Test assignment. See https://github.com/whatwg/fetch/issues/1445
requestInit3.credentials = 'include'
const requestInit4: RequestInit = { body: null }
const requestInit5: RequestInit = {
method: 'GET'
}
const requestInit6: RequestInit = {
method: 'POST'
}

declare const request: Request
declare const headers: Headers
Expand All @@ -44,7 +51,7 @@ expectType<RequestCredentials | undefined>(requestInit.credentials)
expectType<HeadersInit | undefined>(requestInit.headers)
expectType<string | undefined>(requestInit.integrity)
expectType<boolean | undefined>(requestInit.keepalive)
expectType<string | undefined>(requestInit.method)
expectType<HttpMethod | undefined>(requestInit.method)
expectType<RequestMode | undefined>(requestInit.mode)
expectType<RequestRedirect | undefined>(requestInit.redirect)
expectType<string | undefined>(requestInit.referrer)
Expand All @@ -55,6 +62,8 @@ expectType<null | undefined>(requestInit.window)
expectType<Dispatcher | undefined>(requestInit2.dispatcher)

expectType<BodyInit | undefined>(requestInit4.body)
expectType<HttpMethod | undefined>(requestInit5.method)
expectType<HttpMethod | undefined>(requestInit6.method)

expectType<number | undefined>(responseInit.status)
expectType<string | undefined>(responseInit.statusText)
Expand Down
4 changes: 3 additions & 1 deletion types/fetch.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ type RequestDestination =
| 'worker'
| 'xslt'

export type HttpMethod = 'GET' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE' | 'PATCH' | (string & {})

export interface RequestInit {
body?: BodyInit | null
cache?: RequestCache
Expand All @@ -128,7 +130,7 @@ export interface RequestInit {
headers?: HeadersInit
integrity?: string
keepalive?: boolean
method?: string
method?: HttpMethod;
mode?: RequestMode
redirect?: RequestRedirect
referrer?: string
Expand Down
Loading