Skip to content

Commit

Permalink
Merge branch 'canary' into feat/staleness-in-error-overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Feb 17, 2023
2 parents 94eff66 + 752acfe commit dcf268e
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 49 deletions.
51 changes: 29 additions & 22 deletions packages/next/src/shared/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ import type { PreviewData } from 'next/types'
import { COMPILER_NAMES } from './constants'

export type NextComponentType<
C extends BaseContext = NextPageContext,
IP = {},
P = {}
> = ComponentType<P> & {
Context extends BaseContext = NextPageContext,
InitialProps = {},
Props = {}
> = ComponentType<Props> & {
/**
* Used for initial page load data population. Data returned from `getInitialProps` is serialized when server rendered.
* Make sure to return plain `Object` without using `Date`, `Map`, `Set`.
* @param ctx Context of `page`
* @param context Context of `page`
*/
getInitialProps?(context: C): IP | Promise<IP>
getInitialProps?(context: Context): InitialProps | Promise<InitialProps>
}

export type DocumentType = NextComponentType<
Expand Down Expand Up @@ -159,23 +159,23 @@ export interface NextPageContext {
AppTree: AppTreeType
}

export type AppContextType<R extends NextRouter = NextRouter> = {
export type AppContextType<Router extends NextRouter = NextRouter> = {
Component: NextComponentType<NextPageContext>
AppTree: AppTreeType
ctx: NextPageContext
router: R
router: Router
}

export type AppInitialProps<P = any> = {
pageProps: P
export type AppInitialProps<PageProps = any> = {
pageProps: PageProps
}

export type AppPropsType<
R extends NextRouter = NextRouter,
P = {}
> = AppInitialProps<P> & {
Router extends NextRouter = NextRouter,
PageProps = {}
> = AppInitialProps<PageProps> & {
Component: NextComponentType<NextPageContext, any, any>
router: R
router: Router
__N_SSG?: boolean
__N_SSP?: boolean
}
Expand Down Expand Up @@ -230,18 +230,18 @@ type Send<T> = (body: T) => void
/**
* Next `API` route response
*/
export type NextApiResponse<T = any> = ServerResponse & {
export type NextApiResponse<Data = any> = ServerResponse & {
/**
* Send data `any` data in response
*/
send: Send<T>
send: Send<Data>
/**
* Send data `json` data in response
*/
json: Send<T>
status: (statusCode: number) => NextApiResponse<T>
redirect(url: string): NextApiResponse<T>
redirect(status: number, url: string): NextApiResponse<T>
json: Send<Data>
status: (statusCode: number) => NextApiResponse<Data>
redirect(url: string): NextApiResponse<Data>
redirect(status: number, url: string): NextApiResponse<Data>

/**
* Set preview data for Next.js' prerender mode
Expand All @@ -262,13 +262,20 @@ export type NextApiResponse<T = any> = ServerResponse & {
*/
path?: string
}
) => NextApiResponse<T>
) => NextApiResponse<Data>

/**
* Clear preview data for Next.js' prerender mode
*/
clearPreviewData: (options?: { path?: string }) => NextApiResponse<T>
clearPreviewData: (options?: { path?: string }) => NextApiResponse<Data>

/**
* Revalidate a specific page and regenerate it using On-Demand Incremental
* Static Regeneration.
* The path should be an actual path, not a rewritten path. E.g. for
* "/blog/[slug]" this should be "/blog/post-1".
* @link https://nextjs.org/docs/basic-features/data-fetching/incremental-static-regeneration#on-demand-revalidation
*/
revalidate: (
urlPath: string,
opts?: {
Expand Down
60 changes: 33 additions & 27 deletions packages/next/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ export type Redirect =
/**
* `Page` type, use it as a guide to create `pages`.
*/
export type NextPage<P = {}, IP = P> = NextComponentType<NextPageContext, IP, P>
export type NextPage<Props = {}, InitialProps = Props> = NextComponentType<
NextPageContext,
InitialProps,
Props
>

export type FileSizeSuffix = `${
| 'k'
Expand Down Expand Up @@ -135,29 +139,29 @@ export {
export type PreviewData = string | false | object | undefined

export type GetStaticPropsContext<
Q extends ParsedUrlQuery = ParsedUrlQuery,
D extends PreviewData = PreviewData
Params extends ParsedUrlQuery = ParsedUrlQuery,
Preview extends PreviewData = PreviewData
> = {
params?: Q
params?: Params
preview?: boolean
previewData?: D
previewData?: Preview
locale?: string
locales?: string[]
defaultLocale?: string
}

export type GetStaticPropsResult<P> =
| { props: P; revalidate?: number | boolean }
export type GetStaticPropsResult<Props> =
| { props: Props; revalidate?: number | boolean }
| { redirect: Redirect; revalidate?: number | boolean }
| { notFound: true; revalidate?: number | boolean }

export type GetStaticProps<
P extends { [key: string]: any } = { [key: string]: any },
Q extends ParsedUrlQuery = ParsedUrlQuery,
D extends PreviewData = PreviewData
Props extends { [key: string]: any } = { [key: string]: any },
Params extends ParsedUrlQuery = ParsedUrlQuery,
Preview extends PreviewData = PreviewData
> = (
context: GetStaticPropsContext<Q, D>
) => Promise<GetStaticPropsResult<P>> | GetStaticPropsResult<P>
context: GetStaticPropsContext<Params, Preview>
) => Promise<GetStaticPropsResult<Props>> | GetStaticPropsResult<Props>

export type InferGetStaticPropsType<T extends (args: any) => any> = Extract<
Awaited<ReturnType<T>>,
Expand All @@ -169,45 +173,47 @@ export type GetStaticPathsContext = {
defaultLocale?: string
}

export type GetStaticPathsResult<P extends ParsedUrlQuery = ParsedUrlQuery> = {
paths: Array<string | { params: P; locale?: string }>
export type GetStaticPathsResult<
Params extends ParsedUrlQuery = ParsedUrlQuery
> = {
paths: Array<string | { params: Params; locale?: string }>
fallback: boolean | 'blocking'
}

export type GetStaticPaths<P extends ParsedUrlQuery = ParsedUrlQuery> = (
export type GetStaticPaths<Params extends ParsedUrlQuery = ParsedUrlQuery> = (
context: GetStaticPathsContext
) => Promise<GetStaticPathsResult<P>> | GetStaticPathsResult<P>
) => Promise<GetStaticPathsResult<Params>> | GetStaticPathsResult<Params>

export type GetServerSidePropsContext<
Q extends ParsedUrlQuery = ParsedUrlQuery,
D extends PreviewData = PreviewData
Params extends ParsedUrlQuery = ParsedUrlQuery,
Preview extends PreviewData = PreviewData
> = {
req: IncomingMessage & {
cookies: NextApiRequestCookies
}
res: ServerResponse
params?: Q
params?: Params
query: ParsedUrlQuery
preview?: boolean
previewData?: D
previewData?: Preview
resolvedUrl: string
locale?: string
locales?: string[]
defaultLocale?: string
}

export type GetServerSidePropsResult<P> =
| { props: P | Promise<P> }
export type GetServerSidePropsResult<Props> =
| { props: Props | Promise<Props> }
| { redirect: Redirect }
| { notFound: true }

export type GetServerSideProps<
P extends { [key: string]: any } = { [key: string]: any },
Q extends ParsedUrlQuery = ParsedUrlQuery,
D extends PreviewData = PreviewData
Props extends { [key: string]: any } = { [key: string]: any },
Params extends ParsedUrlQuery = ParsedUrlQuery,
Preview extends PreviewData = PreviewData
> = (
context: GetServerSidePropsContext<Q, D>
) => Promise<GetServerSidePropsResult<P>>
context: GetServerSidePropsContext<Params, Preview>
) => Promise<GetServerSidePropsResult<Props>>

export type InferGetServerSidePropsType<T extends (args: any) => any> = Awaited<
Extract<Awaited<ReturnType<T>>, { props: any }>['props']
Expand Down

0 comments on commit dcf268e

Please sign in to comment.