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

Page prop is type never with InferGetStaticPropsType #7159

Closed
1 task
bilco105 opened this issue May 22, 2023 · 0 comments · Fixed by #8229
Closed
1 task

Page prop is type never with InferGetStaticPropsType #7159

bilco105 opened this issue May 22, 2023 · 0 comments · Fixed by #8229
Assignees
Labels
- P3: minor bug An edge case that only affects very specific usage (priority)

Comments

@bilco105
Copy link

What version of astro are you using?

2.5.1

Are you using an SSR adapter? If so, which one?

None

What package manager are you using?

pnpm

What operating system are you using?

Mac

What browser are you using?

Safari

Describe the Bug

This looks to be a repeat of #6507 which was closed, though I'm still seeing the same behaviour.

The following code in src/pages/blog/[...page].astro doesn't infer props correctly, causing page in the snippet below to be typed as never.

export const getStaticPaths = (async ({ paginate }) => {
  const posts = (await getCollection('blog')).sort(
    (a, b) => a.data.pubDate.valueOf() - b.data.pubDate.valueOf()
  );
  return paginate(posts, { pageSize: 10 })
}) satisfies GetStaticPaths

type Props = InferGetStaticPropsType<typeof getStaticPaths>

const { page } = Astro.props as Props

I can work around this by manually typing the Props as follows, but it would be good to not to have keep doing this throughout the project.

interface Props {
  page: Page<CollectionEntry<'blog'>>
}

Issue can be reproduced by running npm run check within the attached Stackblitz

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-xpiyfp?file=src%2Fpages%2Fblog%2F%5B...page%5D.astro

Participation

  • I am willing to submit a pull request for this issue.
@matthewp matthewp self-assigned this Jun 12, 2023
@matthewp matthewp added the - P3: minor bug An edge case that only affects very specific usage (priority) label Jun 12, 2023
@Princesseuh Princesseuh assigned Princesseuh and unassigned matthewp Jul 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P3: minor bug An edge case that only affects very specific usage (priority)
Projects
None yet
3 participants