-
Notifications
You must be signed in to change notification settings - Fork 29k
Add app router types #82439
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
Add app router types #82439
Conversation
When dealing with app router, there were no types available. Instead, the user was supposed to define their own types. This is prone to typos and reduces discoverability of properties. This change introduces some helper types for dealing with App router. This also fixes the `React` import by changing it to a star import. The `react` module has no default export. Instead, Next.js relied on specific TypeScript configurations that may or may not work in some situations.
Allow CI Workflow Run
Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer |
Allow CI Workflow Run
Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer |
Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
) => Metadata | PromiseLike<Metadata> | ||
generateStaticParams?: () => Params[] | PromiseLike<Params[]> | ||
metadata?: Metadata | ||
default: React.ComponentType<PageProps<Params>> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The indentation for the default
property is inconsistent with the other properties in the PageModule
interface. This should be indented to the same level as generateMetadata
, generateStaticParams
, and metadata
to properly define it as a property of the interface:
export interface PageModule<Params = {}> {
generateMetadata?: (
props: PageProps<Params>,
parent: ResolvingMetadata
) => Metadata | PromiseLike<Metadata>
generateStaticParams?: () => Params[] | PromiseLike<Params[]>
metadata?: Metadata
default: React.ComponentType<PageProps<Params>>
}
default: React.ComponentType<PageProps<Params>> | |
default: React.ComponentType<PageProps<Params>> |
Spotted by Diamond
Is this helpful? React 👍 or 👎 to let us know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. Changing the React import makes sense but should be accompanied by a lint rule to prevent future regressions.
The helper types will be addressed by #81396
Failing test suitesCommit: 262c327
Expand output● segment cache (metadata) › regression: prefetch the head if it's missing even if all other data is cached › pages with runtime-prefetchable content and dynamic metadata, using a runtime prefetch
Read more about building and testing Next.js in contributing.md. |
This I look forward to using the alternative using generated types. I’ll close this PR :) |
What?
This change introduces some helper types for dealing with App router.
This also fixes the
React
import by changing it to a star import. Thereact
module has no default export. Instead, Next.js relied on specific TypeScript configurations that may or may not work in some situations.Why?
When dealing with app router, there were no types available. Instead, the user was supposed to define their own types. This is prone to typos and reduces discoverability of properties.
How?
By copying over some types I’ve already been happy to use in my own Next.js project.