Skip to content

[TSX] infer props and params from getStaticPaths#873

Merged
natemoo-re merged 3 commits intomainfrom
feat/tsx-infer-getStaticPaths
Oct 4, 2023
Merged

[TSX] infer props and params from getStaticPaths#873
natemoo-re merged 3 commits intomainfrom
feat/tsx-infer-getStaticPaths

Conversation

@natemoo-re
Copy link
Copy Markdown
Member

@natemoo-re natemoo-re commented Oct 3, 2023

Changes

  • This PR is relevant for consumers of our TSX output (namely language tools)
  • Adds new generated output if an Astro component has a getStaticPaths export
  • Astro.props and Astro.params can be inferred from the return value of getStaticPaths
    • Existing Props definitions take precedence over inferred definitions, so this should be compatible with the existing recommended pattern below:
    type Params = InferGetStaticParamsType<typeof getStaticPaths>;
    type Props = InferGetStaticPropsType<typeof getStaticPaths>;
  • Ideally we'd also be able to inject a satisfies clause for getStaticPaths itself, but that can be left for a follow-up PR

Testing

Tests added

Docs

We should update the docs when this lands upstream in the language tools!

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Oct 3, 2023

🦋 Changeset detected

Latest commit: f6d9524

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@astrojs/compiler Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Comment thread internal/printer/print-to-tsx.go Outdated
Copy link
Copy Markdown
Member

@Princesseuh Princesseuh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work! People will be very happy about this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants