Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix
AppTypegeneric being applied topagePropsinstead ofpropsCloses #42846
Summary
The generic parameter
PonAppType<P>was being applied to thepagePropsproperty of the App component's props instead of to the top-level
props.For example, with:
TypeScript reported
Property 'foo' does not exist on type 'AppPropsType<any, MyInitialProps>'for
props.foo(even thoughfooexists at runtime), whileprops.pageProps.foowas incorrectly allowed (even though
foois not onpagePropsat runtime).This happened because
AppType<P>was defined as:Change
Apply the generic
Pto the top-level props instead of topageProps:Now
props.foois correctly typed (fromP), andpagePropsremains a separateproperty of
props(typedany, sinceAppTypecannot know the page's props).If a user wants to type
pageProps, they can include it inP.Why this is correct
App.getInitialPropspopulates the top-level props of the App component,not
pageProps(only a page'sgetStaticProps/getServerSideProps/getInitialPropspopulatepageProps).pagePropsshould remain a property ofprops, per maintainer guidance.AppTypeonly, soAppProps<P>(the type most_appfiles use, where
Pis the pageProps type) is completely unaffected.Verification
fooonpropsandpagePropsas a separate property.
test/e2e/typescript/pages/_app.tsxusage(
AppType<{ foo: string }>with{ Component, pageProps }) still compiles.AppProps<P>behavior is unchanged.Files changed
packages/next/src/shared/lib/utils.ts