Skip to content

fix(typescript): Update getStaticPaths option to be fully typed#2963

Merged
Princesseuh merged 1 commit intomainfrom
fix/satisfies-getstaticpaths
Mar 31, 2023
Merged

fix(typescript): Update getStaticPaths option to be fully typed#2963
Princesseuh merged 1 commit intomainfrom
fix/satisfies-getstaticpaths

Conversation

@Princesseuh
Copy link
Copy Markdown
Member

What kind of changes does this PR include?

  • New or updated content

Description

This updates the getStaticPaths example in the TypeScript guide to be fully typed. The syntax does look weird because of satisfies, but it's important to show that this is the best way to type getStaticPaths, because typing it normally (using : GetStaticPaths) breaks InferGetStaticParamsType (and its Props equivalent) since it works by inferring the return value (which typing it directly removes the ability to)

@netlify
Copy link
Copy Markdown

netlify bot commented Mar 30, 2023

Deploy Preview for astro-docs-2 ready!

Name Link
🔨 Latest commit 1f32abb
🔍 Latest deploy log https://app.netlify.com/sites/astro-docs-2/deploys/6425522a1311270008841e86
😎 Deploy Preview https://deploy-preview-2963--astro-docs-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

Copy link
Copy Markdown
Member

@delucis delucis left a comment

Choose a reason for hiding this comment

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

LGTM!

Can you use satisfies in a return type? (Couldn’t find it at all in the handbook… only in the announcement blog post.) Would look less weird if we were only annotating the result, but obviously that’s not helpful if you also want the parameters typed.

@Princesseuh
Copy link
Copy Markdown
Member Author

LGTM!

Can you use satisfies in a return type? (Couldn’t find it at all in the handbook… only in the announcement blog post.) Would look less weird if we were only annotating the result, but obviously that’s not helpful if you also want the parameters typed.

I believe you can, but in the case of getStaticPaths, you do want the params typed (for paginate)

Copy link
Copy Markdown
Member

@yanthomasdev yanthomasdev left a comment

Choose a reason for hiding this comment

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

LGTM!

@Princesseuh Princesseuh merged commit 9dacfd9 into main Mar 31, 2023
@Princesseuh Princesseuh deleted the fix/satisfies-getstaticpaths branch March 31, 2023 13:00
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.

3 participants