UNPKG

2.19 kBTypeScriptView Raw
1/// <reference types="node" />
2/// <reference types="react" />
3/// <reference types="react-dom" />
4
5import React from 'react'
6import { ParsedUrlQuery } from 'querystring'
7import { IncomingMessage, ServerResponse } from 'http'
8
9import {
10 NextPageContext,
11 NextComponentType,
12 NextApiResponse,
13 NextApiRequest,
14 NextApiHandler,
15 // @ts-ignore This path is generated at build time and conflicts otherwise
16} from '../dist/next-server/lib/utils'
17
18// @ts-ignore This path is generated at build time and conflicts otherwise
19import next from '../dist/server/next'
20
21// Extend the React types with missing properties
22declare module 'react' {
23 // <html amp=""> support
24 interface HtmlHTMLAttributes<T> extends React.HTMLAttributes<T> {
25 amp?: string
26 }
27
28 // <link nonce=""> support
29 interface LinkHTMLAttributes<T> extends HTMLAttributes<T> {
30 nonce?: string
31 }
32
33 // <style jsx> and <style jsx global> support for styled-jsx
34 interface StyleHTMLAttributes<T> extends HTMLAttributes<T> {
35 jsx?: boolean
36 global?: boolean
37 }
38}
39
40/**
41 * `Page` type, use it as a guide to create `pages`.
42 */
43export type NextPage<P = {}, IP = P> = NextComponentType<NextPageContext, IP, P>
44
45/**
46 * `Config` type, use it for export const config
47 */
48export type PageConfig = {
49 amp?: boolean | 'hybrid'
50 api?: {
51 /**
52 * The byte limit of the body. This is the number of bytes or any string
53 * format supported by `bytes`, for example `1000`, `'500kb'` or `'3mb'`.
54 */
55 bodyParser?: { sizeLimit?: number | string } | false
56 }
57}
58
59export {
60 NextPageContext,
61 NextComponentType,
62 NextApiResponse,
63 NextApiRequest,
64 NextApiHandler,
65}
66
67export type GetStaticProps = (ctx: {
68 params?: ParsedUrlQuery
69 preview?: boolean
70 previewData?: any
71}) => Promise<{
72 props: { [key: string]: any }
73 revalidate?: number | boolean
74}>
75
76export type GetStaticPaths = () => Promise<{
77 paths: Array<string | { params: ParsedUrlQuery }>
78 fallback: boolean
79}>
80
81export type GetServerSideProps = (context: {
82 req: IncomingMessage
83 res: ServerResponse
84 params?: ParsedUrlQuery
85 query: ParsedUrlQuery
86 preview?: boolean
87 previewData?: any
88}) => Promise<{ [key: string]: any }>
89
90export default next