Skip to content

Commit

Permalink
Add NextApiHandler type (#10573)
Browse files Browse the repository at this point in the history
* Add NextApiHandler type

* Fix formatting

Co-authored-by: Joe Haddad <timer150@gmail.com>
  • Loading branch information
martpie and Timer committed Feb 19, 2020
1 parent db04cc5 commit 0a5cc30
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
8 changes: 8 additions & 0 deletions packages/next/next-server/lib/utils.ts
Expand Up @@ -219,6 +219,14 @@ export type NextApiResponse<T = any> = ServerResponse & {
clearPreviewData: () => NextApiResponse<T>
}

/**
* Next `API` route handler
*/
export type NextApiHandler<T = any> = (
req: NextApiRequest,
res: NextApiResponse<T>
) => void

/**
* Utils
*/
Expand Down
9 changes: 8 additions & 1 deletion packages/next/types/index.d.ts
Expand Up @@ -9,6 +9,7 @@ import {
NextComponentType,
NextApiResponse,
NextApiRequest,
NextApiHandler,
// @ts-ignore This path is generated at build time and conflicts otherwise
} from '../dist/next-server/lib/utils'

Expand Down Expand Up @@ -53,6 +54,12 @@ export type PageConfig = {
}
}

export { NextPageContext, NextComponentType, NextApiResponse, NextApiRequest }
export {
NextPageContext,
NextComponentType,
NextApiResponse,
NextApiRequest,
NextApiHandler,
}

export default next

0 comments on commit 0a5cc30

Please sign in to comment.