Skip to content

Commit

Permalink
Add typing to support nextjs api routes
Browse files Browse the repository at this point in the history
  • Loading branch information
garth committed Apr 23, 2020
1 parent 1b4e90a commit efeb7fc
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ function createCookie(
* @param options
*/
export function parseCookies(
ctx?: Pick<next.NextPageContext, 'req'> | null | undefined,
ctx?:
| Pick<next.NextPageContext, 'req'>
| { req: next.NextApiRequest }
| null
| undefined,
options?: cookie.CookieParseOptions,
) {
if (ctx && ctx.req && ctx.req.headers && ctx.req.headers.cookie) {
Expand All @@ -104,7 +108,11 @@ export function parseCookies(
* @param options
*/
export function setCookie(
ctx: Pick<next.NextPageContext, 'res'> | null | undefined,
ctx:
| Pick<next.NextPageContext, 'res'>
| { res: next.NextApiResponse }
| null
| undefined,
name: string,
value: string,
options: cookie.CookieSerializeOptions,
Expand Down Expand Up @@ -152,7 +160,11 @@ export function setCookie(
* @param options
*/
export function destroyCookie(
ctx: next.NextPageContext | null | undefined,
ctx:
| Pick<next.NextPageContext, 'res'>
| { res: next.NextApiResponse }
| null
| undefined,
name: string,
options?: cookie.CookieSerializeOptions,
) {
Expand Down

0 comments on commit efeb7fc

Please sign in to comment.