Skip to content

Commit

Permalink
Improve types for getStaticPaths, fixes dead links (#3755)
Browse files Browse the repository at this point in the history
  • Loading branch information
Princesseuh authored Jun 29, 2022
1 parent aaf0cd8 commit 40be96d
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions packages/astro/src/@types/astro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,8 @@ export type GetHydrateCallback = () => Promise<() => void | Promise<void>>;

/**
* getStaticPaths() options
* Docs: https://docs.astro.build/reference/api-reference/#getstaticpaths
*
* [Astro Reference](https://docs.astro.build/en/reference/api-reference/#getstaticpaths)
*/ export interface GetStaticPathsOptions {
paginate: PaginateFunction;
/**
Expand All @@ -793,6 +794,18 @@ export type GetStaticPathsResultKeyed = GetStaticPathsResult & {
keyed: Map<string, GetStaticPathsItem>;
};

/**
* Return an array of pages to generate for a [dynamic route](https://docs.astro.build/en/core-concepts/routing/#dynamic-routes). (**SSG Only**)
*
* [Astro Reference](https://docs.astro.build/en/reference/api-reference/#getstaticpaths)
*/
export type GetStaticPaths = (
options: GetStaticPathsOptions
) =>
| Promise<GetStaticPathsResult | GetStaticPathsResult[]>
| GetStaticPathsResult
| GetStaticPathsResult[];

export interface HydrateOptions {
name: string;
value?: string;
Expand Down Expand Up @@ -820,15 +833,17 @@ export interface MarkdownParserResponse extends MarkdownRenderingResult {

/**
* The `content` prop given to a Layout
* https://docs.astro.build/guides/markdown-content/#markdown-layouts
*
* [Astro reference](https://docs.astro.build/en/guides/markdown-content/#markdown-layouts)
*/
export type MarkdownContent<T extends Record<string, any> = Record<string, any>> = T & {
astro: MarkdownMetadata;
};

/**
* paginate() Options
* Docs: https://docs.astro.build/guides/pagination/#calling-the-paginate-function
*
* [Astro reference](https://docs.astro.build/en/reference/api-reference/#paginate)
*/
export interface PaginateOptions {
/** the number of items per-page (default: `10`) */
Expand All @@ -840,8 +855,9 @@ export interface PaginateOptions {
}

/**
* Page Prop
* Docs: https://docs.astro.build/guides/pagination/#using-the-page-prop
* Represents a single page of data in a paginated collection
*
* [Astro reference](https://docs.astro.build/en/reference/api-reference/#the-pagination-page-prop)
*/
export interface Page<T = any> {
/** result */
Expand Down Expand Up @@ -869,7 +885,7 @@ export interface Page<T = any> {
};
}

export type PaginateFunction = (data: [], args?: PaginateOptions) => GetStaticPathsResult;
export type PaginateFunction = (data: any[], args?: PaginateOptions) => GetStaticPathsResult;

export type Params = Record<string, string | number | undefined>;

Expand Down

0 comments on commit 40be96d

Please sign in to comment.