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

feat(paginate): Return exact types from paginate() #8229

Merged
merged 4 commits into from
Aug 28, 2023

Conversation

Princesseuh
Copy link
Member

Changes

paginate() currently returns a naive GetStaticPathsResult which override the actual types it returns, this PR makes it so it actually returns what is being inputted, which because of the fact that it allows you to inject params and props, made this strangely hard. Maybe there's an easier way to do it, but I couldn't figure it out

This is similar to #8048, but it doesn't require user to manually type PaginateFunction

This PR also fixes #7159, mostly by accident

Testing

Tested manually

Docs

N/A. Docs document the return values of paginate(), so this really just makes it more accurate to what's currently described

@Princesseuh Princesseuh requested a review from a team as a code owner August 25, 2023 15:05
@changeset-bot
Copy link

changeset-bot bot commented Aug 25, 2023

🦋 Changeset detected

Latest commit: 65e3007

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

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

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Aug 25, 2023
@@ -57,7 +57,7 @@ declare module 'astro:assets' {
};

type WithRequired<T, K extends keyof T> = T & { [P in K]-?: T[P] };
type Simplify<T> = { [KeyType in keyof T]: T[KeyType] };
type Simplify<T> = { [KeyType in keyof T]: T[KeyType] } & {};
Copy link
Member Author

Choose a reason for hiding this comment

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

Just a small fix, eventually when we refactor types, we should probably have a "internal-type-utils" file somewhere with this and all the other nonsense I add

paginate: generatePaginateFunction(route),
// Q: Why the cast?
// A: So users downstream can have nicer typings, we have to make some sacrifice in our internal typings, which necessitate a cast here
paginate: generatePaginateFunction(route) as PaginateFunction,
Copy link
Member Author

Choose a reason for hiding this comment

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

I think there is a way to make this work without the cast, but I couldn't for my life figure it out. I think the disconnect between the internal implementation and what the user actually uses makes it very hard to do in one type

Copy link
Member

Choose a reason for hiding this comment

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

Seems like a reasonable tradeoff!

Copy link
Member

@natemoo-re natemoo-re left a comment

Choose a reason for hiding this comment

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

Looks great, approved!

Would you mind closing out #8048 and the related issue after merging this since they overlap?

@matthewp matthewp merged commit ffc9e2d into main Aug 28, 2023
14 checks passed
@matthewp matthewp deleted the feat/exact-paginate-types branch August 28, 2023 16:02
This was referenced Aug 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Page prop is type never with InferGetStaticPropsType
3 participants