Skip to content

Commit

Permalink
Update TypeScript API Route example (#44517)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
abir-taheer and ijjk committed Jan 3, 2023
1 parent 08fb7b5 commit 0549a46
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions docs/basic-features/typescript.md
Expand Up @@ -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' })
}
```
Expand All @@ -117,7 +117,10 @@ type Data = {
name: string
}

export default (req: NextApiRequest, res: NextApiResponse<Data>) => {
export default function handler(
req: NextApiRequest,
res: NextApiResponse<Data>
) {
res.status(200).json({ name: 'John Doe' })
}
```
Expand Down

0 comments on commit 0549a46

Please sign in to comment.