未验证 提交 8fdb93d7 编写于 作者: G Gergo Tolnai 提交者: GitHub

Docs(api-middlewares): use typings for serialize options from @types/cookie (#17285)

上级 beeeba09
......@@ -124,23 +124,18 @@ For better type-safety, it is not recommended to extend the `req` and `res` obje
```ts
// utils/cookies.ts
import { serialize } from 'cookie'
import { serialize, CookieSerializeOptions } from 'cookie'
import { NextApiResponse } from 'next'
/**
* This sets `cookie` using the `res` object
*/
type Options = {
expires?: Date
maxAge?: number
}
export const setCookie = (
res: NextApiResponse,
name: string,
value: unknown,
options: Options = {}
options: CookieSerializeOptions = {}
) => {
const stringValue =
typeof value === 'object' ? 'j:' + JSON.stringify(value) : String(value)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册