Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more JSDoc to types #46897

Merged
merged 1 commit into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions packages/next/src/server/config-shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ export interface ExperimentalConfig {
nextScriptWorkers?: boolean
scrollRestoration?: boolean
externalDir?: boolean
/**
* The App Router (app directory) enables support for layouts, Server Components, streaming, and colocated data fetching.
* @see https://beta.nextjs.org/docs/api-reference/next.config.js#appdir
*/
appDir?: boolean
amp?: {
optimizer?: any
Expand Down Expand Up @@ -184,7 +188,10 @@ export interface ExperimentalConfig {
adjustFontFallbacks?: boolean
adjustFontFallbacksWithSizeAdjust?: boolean

// A list of packages that should be treated as external in the RSC server build
/**
* A list of packages that should be treated as external in the RSC server build.
* @see https://beta.nextjs.org/docs/api-reference/next.config.js#servercomponentsexternalpackages
*/
serverComponentsExternalPackages?: string[]

fontLoaders?: Array<{ loader: string; options?: any }>
Expand All @@ -209,10 +216,18 @@ export interface ExperimentalConfig {
/** in `MB` */
memoryLimit?: number
}

/**
* For use with `@next/mdx`. Compile MDX files using the new Rust compiler.
* @see https://beta.nextjs.org/docs/api-reference/next.config.js#mdxrs
*/
mdxRs?: boolean

// Generate Route types and enable type checking for Link and Router.push, etc.
// This option requires `appDir` to be enabled first.
/**
* Generate Route types and enable type checking for Link and Router.push, etc.
* This option requires `appDir` to be enabled first.
* @see https://beta.nextjs.org/docs/api-reference/next.config.js#typedroutes
*/
typedRoutes?: boolean

/**
Expand Down Expand Up @@ -554,7 +569,11 @@ export interface NextConfig extends Record<string, any> {
*/
output?: 'standalone' | 'export'

// A list of packages that should always be transpiled and bundled in the server
/**
* Automatically transpile and bundle dependencies from local packages (like monorepos) or from external dependencies (`node_modules`). This replaces the
* `next-transpile-modules` package.
* @see [transpilePackages](https://beta.nextjs.org/docs/api-reference/next.config.js#transpilepackages)
*/
transpilePackages?: string[]

skipMiddlewareUrlNormalize?: boolean
Expand Down
52 changes: 52 additions & 0 deletions packages/next/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ export {

export type PreviewData = string | false | object | undefined

/**
* Context object passed into `getStaticProps`.
* @link https://nextjs.org/docs/api-reference/data-fetching/get-static-props#context-parameter
*/
export type GetStaticPropsContext<
Params extends ParsedUrlQuery = ParsedUrlQuery,
Preview extends PreviewData = PreviewData
Expand All @@ -150,11 +154,26 @@ export type GetStaticPropsContext<
defaultLocale?: string
}

/**
* The return type of `getStaticProps`.
* @link https://nextjs.org/docs/api-reference/data-fetching/get-static-props#getstaticprops-return-values
*/
export type GetStaticPropsResult<Props> =
| { props: Props; revalidate?: number | boolean }
| { redirect: Redirect; revalidate?: number | boolean }
| { notFound: true; revalidate?: number | boolean }

/**
* Static Site Generation feature for Next.js.
* @link https://nextjs.org/docs/basic-features/data-fetching/get-static-props
* @link https://nextjs.org/docs/basic-features/typescript#static-generation-and-server-side-rendering
* @example
* ```ts
* export const getStaticProps: GetStaticProps = async (context) => {
* // ...
* }
* ```
*/
export type GetStaticProps<
Props extends { [key: string]: any } = { [key: string]: any },
Params extends ParsedUrlQuery = ParsedUrlQuery,
Expand All @@ -173,17 +192,36 @@ export type GetStaticPathsContext = {
defaultLocale?: string
}

/**
* The return type of `getStaticPaths`.
* @link https://nextjs.org/docs/api-reference/data-fetching/get-static-paths#getstaticpaths-return-values
*/
export type GetStaticPathsResult<
Params extends ParsedUrlQuery = ParsedUrlQuery
> = {
paths: Array<string | { params: Params; locale?: string }>
fallback: boolean | 'blocking'
}

/**
* Define a list of paths to be statically generated if dynamic routes exist.
* @link https://nextjs.org/docs/basic-features/data-fetching/get-static-paths
* @link https://nextjs.org/docs/basic-features/typescript#static-generation-and-server-side-rendering
* @example
* ```ts
* export const getStaticPaths: GetStaticPaths = async () => {
* // ...
* }
* ```
*/
export type GetStaticPaths<Params extends ParsedUrlQuery = ParsedUrlQuery> = (
context: GetStaticPathsContext
) => Promise<GetStaticPathsResult<Params>> | GetStaticPathsResult<Params>

/**
* Context object passed into `getServerSideProps`.
* @link https://nextjs.org/docs/api-reference/data-fetching/get-server-side-props#context-parameter
*/
export type GetServerSidePropsContext<
Params extends ParsedUrlQuery = ParsedUrlQuery,
Preview extends PreviewData = PreviewData
Expand All @@ -202,11 +240,25 @@ export type GetServerSidePropsContext<
defaultLocale?: string
}

/**
* The return type of `getServerSideProps`.
* @link https://nextjs.org/docs/api-reference/data-fetching/get-server-side-props#getserversideprops-return-values
*/
export type GetServerSidePropsResult<Props> =
| { props: Props | Promise<Props> }
| { redirect: Redirect }
| { notFound: true }

/**
* Server-side Rendering feature for Next.js.
* @link https://nextjs.org/docs/basic-features/data-fetching/get-server-side-props
* @link https://nextjs.org/docs/basic-features/typescript#static-generation-and-server-side-rendering
* @example
* ```ts
* export const getServerSideProps: GetServerSideProps = async (context) => {
* // ...
* }
*/
export type GetServerSideProps<
Props extends { [key: string]: any } = { [key: string]: any },
Params extends ParsedUrlQuery = ParsedUrlQuery,
Expand Down