diff --git a/test/types/cookies.test-d.ts b/test/types/cookies.test-d.ts new file mode 100644 index 00000000000..337e5172a2e --- /dev/null +++ b/test/types/cookies.test-d.ts @@ -0,0 +1,19 @@ +import { expectError, expectType } from 'tsd' +import { Headers, deleteCookie } from '../..' + +const headers = new Headers() + +// `path` and `domain` should be accepted as deleteCookie attributes. +expectType(deleteCookie(headers, 'session', { + domain: 'example.com', + path: '/' +})) + +expectType(deleteCookie(headers, 'session', { path: '/' })) +expectType(deleteCookie(headers, 'session', { domain: 'example.com' })) + +// `name` should not be accepted because the cookie name is the second positional argument. +expectError(deleteCookie(headers, 'session', { + domain: 'example.com', + name: 'session' +})) diff --git a/types/cookies.d.ts b/types/cookies.d.ts index f746d35853f..d8dc1f60c57 100644 --- a/types/cookies.d.ts +++ b/types/cookies.d.ts @@ -18,7 +18,7 @@ export interface Cookie { export function deleteCookie ( headers: Headers, name: string, - attributes?: { name?: string, domain?: string } + attributes?: { path?: string, domain?: string } ): void export function getCookies (headers: Headers): Record