From efeb7fc3201c39c8f6162cdea791203f4258b887 Mon Sep 17 00:00:00 2001 From: Garth Williams Date: Thu, 23 Apr 2020 23:40:53 +0200 Subject: [PATCH] Add typing to support nextjs api routes --- src/index.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index 617d4178..ad1a738f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -80,7 +80,11 @@ function createCookie( * @param options */ export function parseCookies( - ctx?: Pick | null | undefined, + ctx?: + | Pick + | { req: next.NextApiRequest } + | null + | undefined, options?: cookie.CookieParseOptions, ) { if (ctx && ctx.req && ctx.req.headers && ctx.req.headers.cookie) { @@ -104,7 +108,11 @@ export function parseCookies( * @param options */ export function setCookie( - ctx: Pick | null | undefined, + ctx: + | Pick + | { res: next.NextApiResponse } + | null + | undefined, name: string, value: string, options: cookie.CookieSerializeOptions, @@ -152,7 +160,11 @@ export function setCookie( * @param options */ export function destroyCookie( - ctx: next.NextPageContext | null | undefined, + ctx: + | Pick + | { res: next.NextApiResponse } + | null + | undefined, name: string, options?: cookie.CookieSerializeOptions, ) {