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

Fix InferGetStaticParamsType and InferGetStaticPropsType not working with sync getStaticPaths #6711

Merged
merged 3 commits into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 5 additions & 0 deletions .changeset/odd-falcons-exist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fix InferGetStaticParamsType and InferGetStaticPropsType not working when getStaticPaths wasn't async
18 changes: 11 additions & 7 deletions packages/astro/src/@types/astro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1197,19 +1197,21 @@ export type GetStaticPaths = (
*
* @example
* ```ts
* export async function getStaticPaths() {
* import { GetStaticPaths } from 'astro';
*
* export const getStaticPaths = (() => {
* return results.map((entry) => ({
* params: { slug: entry.slug },
* }));
* }
* }) satisfies GetStaticPaths;
*
* type Params = InferGetStaticParamsType<typeof getStaticPaths>;
* // ^? { slug: string; }
*
* 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
Expand All @@ -1222,23 +1224,25 @@ export type InferGetStaticParamsType<T> = T extends () => Promise<infer R>
*
* @example
* ```ts
* export async function getStaticPaths() {
* import { GetStaticPaths } from 'astro';
*
* export const getStaticPaths = (() => {
* return results.map((entry) => ({
* params: { slug: entry.slug },
* props: {
* propA: true,
* 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
Expand Down