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
bug(typedef): AppType typedef changed in 12.3 #40371
Comments
Appears to be related to this typedef change 12.2: export declare type AppInitialProps = {
pageProps: any;
};
export declare type AppPropsType<R extends NextRouter = NextRouter, P = {}> = AppInitialProps & {
Component: NextComponentType<NextPageContext, any, P>;
router: R;
__N_SSG?: boolean;
__N_SSP?: boolean;
__N_RSC?: boolean;
}; 12.3: export declare type AppInitialProps<P = any> = {
pageProps: P;
};
export declare type AppPropsType<R extends NextRouter = NextRouter, P = {}> = AppInitialProps<P> & {
Component: NextComponentType<NextPageContext, any, any>;
router: R;
__N_SSG?: boolean;
__N_SSP?: boolean;
__N_RSC?: boolean;
}; |
To be clear i think this is a very good improvement and seems like it would allow for a more typesafe usage in the root app. Maybe the AppType should be a generic like NextPage, or React.FC and letting me pass in the props like const MyApp: AppType<{ session: Session }> = ... |
Hi, import type { AppProps } from "next/app"
import type { Session } from "next-auth"
import { SessionProvider } from "next-auth/react"
export default function MyApp(appProps: AppProps<{ session: Session }>) {
const {
Component,
pageProps: { session, ...pageProps },
} = appProps
return (
<SessionProvider session={session}>
<Component {...pageProps} />
</SessionProvider>
)
} |
Thanks for the response. I've always thought the import path has been weird and could probably have guessed it wasn't for official usage. However... typing arrow function components like Would you accept this as a feature request in exposing this type similar to the AppProps and allow it as a generic import type { AppType } from "next/app";
const MyApp: AppType<{ session: Session }> = ({
Component,
pageProps
}) => { ... };
export default trpc.withTRPC(MyApp); // example The alternative would be to just type the return type explicitly but not as clean imo import type { AppProps } from "next/app";
const MyApp = (
{ Component, pageProps}: AppProps<{ session: Session }>
): JSX.Element => { ...} |
Yes, it makes more sense as a feature request, I started working on it already. See #40391 |
An alternative solution to #40371 Ref: #38867, t3-oss/create-t3-app#412, t3-oss/create-t3-app#414 ## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have helpful link attached, see `contributing.md` ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have helpful link attached, see `contributing.md` ## Documentation / Examples - [ ] Make sure the linting passes by running `pnpm lint` - [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Verify canary release
Provide environment information
What browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
Describe the Bug
When bumping version to Next 12.3.0 we ran into some troubles with the AppType typedefinition:
The AppType typedefinition and specifically the pageProps seems to have been broken in 12.3.0 and the pageProps now evaluates to {}:
Expected Behavior
I am not sure if this is a bug or if it's intended, but this change is not present in the changelog and seems to be a "breaking" one worth noting. Maybe we are required to augment some part to make it work with 3rd party dependencies?
Link to reproduction
https://github.com/juliusmarminge/apptype-repro
To Reproduce
Create a new next-app (using reproduction template):
Install NextAuth:
Create
pages/_app.tsx
with the following content:Hover pageProps, it evaluates to {} and the pageProps.session will error. This was not an issue in 12.2.5.
The text was updated successfully, but these errors were encountered: