From 0549a466325c38d82c11a1aaf72ea0452b128b2f Mon Sep 17 00:00:00 2001 From: Abir Taheer <40152590+abir-taheer@users.noreply.github.com> Date: Tue, 3 Jan 2023 15:03:44 -0500 Subject: [PATCH] Update TypeScript API Route example (#44517) The existing example causes issues with eslint's `eslintimport/no-anonymous-default-export` rule that come pre-enabled with `create-next-app`. Added a name to the api handler function before setting it as the default export. ## Documentation / Examples - [x] Make sure the linting passes by running `pnpm build && pnpm lint` - [x] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md) Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com> --- docs/basic-features/typescript.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/basic-features/typescript.md b/docs/basic-features/typescript.md index 5eb1495ec894..35ab23da4363 100644 --- a/docs/basic-features/typescript.md +++ b/docs/basic-features/typescript.md @@ -103,7 +103,7 @@ The following is an example of how to use the built-in types for API routes: ```ts import type { NextApiRequest, NextApiResponse } from 'next' -export default (req: NextApiRequest, res: NextApiResponse) => { +export default function handler(req: NextApiRequest, res: NextApiResponse) { res.status(200).json({ name: 'John Doe' }) } ``` @@ -117,7 +117,10 @@ type Data = { name: string } -export default (req: NextApiRequest, res: NextApiResponse) => { +export default function handler( + req: NextApiRequest, + res: NextApiResponse +) { res.status(200).json({ name: 'John Doe' }) } ```