diff options
-rw-r--r-- | .changeset/odd-falcons-exist.md | 5 | ||||
-rw-r--r-- | packages/astro/src/@types/astro.ts | 18 |
2 files changed, 16 insertions, 7 deletions
diff --git a/.changeset/odd-falcons-exist.md b/.changeset/odd-falcons-exist.md new file mode 100644 index 000000000..386a6e11c --- /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 20aee729d..0064994d8 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<typeof getStaticPaths>; * // ^? { slug: string; } @@ -1209,7 +1211,7 @@ export type GetStaticPaths = ( * const { slug } = Astro.params as Params; * ``` */ -export type InferGetStaticParamsType<T> = T extends () => Promise<infer R> +export type InferGetStaticParamsType<T> = T extends () => infer R | Promise<infer R> ? R extends Array<infer U> ? U extends { params: infer P } ? P @@ -1222,7 +1224,9 @@ export type InferGetStaticParamsType<T> = T extends () => Promise<infer R> * * @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> = T extends () => Promise<infer R> * propB: 42 * }, * })); - * } + * }) satisfies GetStaticPaths; * * type Props = InferGetStaticPropsType<typeof getStaticPaths>; * // ^? { propA: boolean; propB: number; } * - * const { propA, propB } = Astro.props as Props; + * const { propA, propB } = Astro.props; * ``` */ -export type InferGetStaticPropsType<T> = T extends () => Promise<infer R> +export type InferGetStaticPropsType<T> = T extends () => infer R | Promise<infer R> ? R extends Array<infer U> ? U extends { props: infer P } ? P |