1 |
|
2 |
|
3 |
|
4 |
|
5 | import React from 'react'
|
6 | import { ParsedUrlQuery } from 'querystring'
|
7 | import { IncomingMessage, ServerResponse } from 'http'
|
8 |
|
9 | import {
|
10 | NextPageContext,
|
11 | NextComponentType,
|
12 | NextApiResponse,
|
13 | NextApiRequest,
|
14 | NextApiHandler,
|
15 |
|
16 | } from '../dist/next-server/lib/utils'
|
17 |
|
18 | import {
|
19 | NextApiRequestCookies,
|
20 |
|
21 | } from '../dist/next-server/server/api-utils'
|
22 |
|
23 |
|
24 | import next from '../dist/server/next'
|
25 |
|
26 |
|
27 | declare module 'react' {
|
28 |
|
29 | interface HtmlHTMLAttributes<T> extends React.HTMLAttributes<T> {
|
30 | amp?: string
|
31 | }
|
32 |
|
33 |
|
34 | interface LinkHTMLAttributes<T> extends HTMLAttributes<T> {
|
35 | nonce?: string
|
36 | }
|
37 |
|
38 |
|
39 | interface StyleHTMLAttributes<T> extends HTMLAttributes<T> {
|
40 | jsx?: boolean
|
41 | global?: boolean
|
42 | }
|
43 | }
|
44 |
|
45 | export type Redirect =
|
46 | | {
|
47 | statusCode: 301 | 302 | 303 | 307 | 308
|
48 | destination: string
|
49 | basePath?: false
|
50 | }
|
51 | | {
|
52 | permanent: boolean
|
53 | destination: string
|
54 | basePath?: false
|
55 | }
|
56 |
|
57 |
|
58 |
|
59 |
|
60 | export type NextPage<P = {}, IP = P> = NextComponentType<NextPageContext, IP, P>
|
61 |
|
62 |
|
63 |
|
64 |
|
65 | export type PageConfig = {
|
66 | amp?: boolean | 'hybrid'
|
67 | api?: {
|
68 | |
69 |
|
70 |
|
71 |
|
72 | bodyParser?: { sizeLimit?: number | string } | false
|
73 | |
74 |
|
75 |
|
76 |
|
77 |
|
78 | externalResolver?: true
|
79 | }
|
80 | env?: Array<string>
|
81 | unstable_runtimeJS?: false
|
82 | unstable_JsPreload?: false
|
83 | }
|
84 |
|
85 | export {
|
86 | NextPageContext,
|
87 | NextComponentType,
|
88 | NextApiResponse,
|
89 | NextApiRequest,
|
90 | NextApiHandler,
|
91 | }
|
92 |
|
93 | export type PreviewData = string | false | object | undefined
|
94 |
|
95 | export type GetStaticPropsContext<Q extends ParsedUrlQuery = ParsedUrlQuery> = {
|
96 | params?: Q
|
97 | preview?: boolean
|
98 | previewData?: PreviewData
|
99 | locale?: string
|
100 | locales?: string[]
|
101 | defaultLocale?: string
|
102 | }
|
103 |
|
104 | export type GetStaticPropsResult<P> =
|
105 | | { props: P; revalidate?: number | boolean }
|
106 | | { redirect: Redirect; revalidate?: number | boolean }
|
107 | | { notFound: true }
|
108 |
|
109 | export type GetStaticProps<
|
110 | P extends { [key: string]: any } = { [key: string]: any },
|
111 | Q extends ParsedUrlQuery = ParsedUrlQuery
|
112 | > = (
|
113 | context: GetStaticPropsContext<Q>
|
114 | ) => Promise<GetStaticPropsResult<P>> | GetStaticPropsResult<P>
|
115 |
|
116 | export type InferGetStaticPropsType<T> = T extends GetStaticProps<infer P, any>
|
117 | ? P
|
118 | : T extends (
|
119 | context?: GetStaticPropsContext<any>
|
120 | ) => Promise<GetStaticPropsResult<infer P>> | GetStaticPropsResult<infer P>
|
121 | ? P
|
122 | : never
|
123 |
|
124 | export type GetStaticPathsContext = {
|
125 | locales?: string[]
|
126 | defaultLocale?: string
|
127 | }
|
128 |
|
129 | export type GetStaticPathsResult<P extends ParsedUrlQuery = ParsedUrlQuery> = {
|
130 | paths: Array<string | { params: P; locale?: string }>
|
131 | fallback: boolean | 'blocking'
|
132 | }
|
133 |
|
134 | export type GetStaticPaths<P extends ParsedUrlQuery = ParsedUrlQuery> = (
|
135 | context: GetStaticPathsContext
|
136 | ) => Promise<GetStaticPathsResult<P>> | GetStaticPathsResult<P>
|
137 |
|
138 | export type GetServerSidePropsContext<
|
139 | Q extends ParsedUrlQuery = ParsedUrlQuery
|
140 | > = {
|
141 | req: IncomingMessage & {
|
142 | cookies: NextApiRequestCookies
|
143 | }
|
144 | res: ServerResponse
|
145 | params?: Q
|
146 | query: ParsedUrlQuery
|
147 | preview?: boolean
|
148 | previewData?: PreviewData
|
149 | resolvedUrl: string
|
150 | locale?: string
|
151 | locales?: string[]
|
152 | defaultLocale?: string
|
153 | }
|
154 |
|
155 | export type GetServerSidePropsResult<P> =
|
156 | | { props: P }
|
157 | | { redirect: Redirect }
|
158 | | { notFound: true }
|
159 |
|
160 | export type GetServerSideProps<
|
161 | P extends { [key: string]: any } = { [key: string]: any },
|
162 | Q extends ParsedUrlQuery = ParsedUrlQuery
|
163 | > = (
|
164 | context: GetServerSidePropsContext<Q>
|
165 | ) => Promise<GetServerSidePropsResult<P>>
|
166 |
|
167 | export type InferGetServerSidePropsType<T> = T extends GetServerSideProps<
|
168 | infer P,
|
169 | any
|
170 | >
|
171 | ? P
|
172 | : T extends (
|
173 | context?: GetServerSidePropsContext<any>
|
174 | ) => Promise<GetServerSidePropsResult<infer P>>
|
175 | ? P
|
176 | : never
|
177 |
|
178 | export default next
|