diff --git a/.changeset/odd-falcons-exist.md b/.changeset/odd-falcons-exist.md new file mode 100644 index 0000000000..386a6e11cf --- /dev/null +++ b/.changeset/odd-falcons-exist.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fix InferGetStaticParamsType and InferGetStaticPropsType not working when getStaticPaths wasn't async diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts index 20aee729d9..0064994d87 100644 --- a/packages/astro/src/@types/astro.ts +++ b/packages/astro/src/@types/astro.ts @@ -1197,11 +1197,13 @@ export type GetStaticPaths = ( * * @example * ```ts - * export async function getStaticPaths() { + * import type { GetStaticPaths } from 'astro'; + * + * export const getStaticPaths = (() => { * return results.map((entry) => ({ * params: { slug: entry.slug }, * })); - * } + * }) satisfies GetStaticPaths; * * type Params = InferGetStaticParamsType; * // ^? { slug: string; } @@ -1209,7 +1211,7 @@ export type GetStaticPaths = ( * const { slug } = Astro.params as Params; * ``` */ -export type InferGetStaticParamsType = T extends () => Promise +export type InferGetStaticParamsType = T extends () => infer R | Promise ? R extends Array ? U extends { params: infer P } ? P @@ -1222,7 +1224,9 @@ export type InferGetStaticParamsType = T extends () => Promise * * @example * ```ts - * export async function getStaticPaths() { + * import type { GetStaticPaths } from 'astro'; + * + * export const getStaticPaths = (() => { * return results.map((entry) => ({ * params: { slug: entry.slug }, * props: { @@ -1230,15 +1234,15 @@ export type InferGetStaticParamsType = T extends () => Promise * propB: 42 * }, * })); - * } + * }) satisfies GetStaticPaths; * * type Props = InferGetStaticPropsType; * // ^? { propA: boolean; propB: number; } * - * const { propA, propB } = Astro.props as Props; + * const { propA, propB } = Astro.props; * ``` */ -export type InferGetStaticPropsType = T extends () => Promise +export type InferGetStaticPropsType = T extends () => infer R | Promise ? R extends Array ? U extends { props: infer P } ? P