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

Next.js 12.3.0 AppProps generic breaks appWithTranslation type #1944

Closed
matchatype opened this issue Sep 9, 2022 · 17 comments · Fixed by #1987
Closed

Next.js 12.3.0 AppProps generic breaks appWithTranslation type #1944

matchatype opened this issue Sep 9, 2022 · 17 comments · Fixed by #1987

Comments

@matchatype
Copy link

matchatype commented Sep 9, 2022

Next.js 12.3.0 #38867 introduces the use of a generic for AppProps type, that is incompatible with appWithTranslation type.

To Reproduce

The following example causes a TypeScript error (TS2345):Argument of type '({ Component, pageProps }: AppProps<{ session: Session;}>) => JSX.Element' is not assignable to parameter of type 'ComponentType<AppProps>'.

const App = ({Component, pageProps}: AppProps<{session: Session}>) => (
  <SessionProvider session={pageProps.session}>
    <ThemeProvider>
      <Component {...pageProps} />
    </ThemeProvider>
  </SessionProvider>
)

export default appWithTranslation(App)
@adrai
Copy link
Member

adrai commented Sep 9, 2022

Would you like to send a Pull Request to address this?

gazs added a commit to gazs/next-i18next that referenced this issue Sep 12, 2022
@gazs
Copy link

gazs commented Sep 12, 2022

@adrai @matchatype I've opened a PR that apparently addresses the issue: #1948

@adrai
Copy link
Member

adrai commented Sep 12, 2022

@adrai @matchatype I've opened a PR that apparently addresses the issue: #1948

@matchatype let me know if this works for you, then we'll merge that PR and release a new version

@matchatype
Copy link
Author

@gazs I don't think you want to do that. What you want is extend SSRConfig to allow whatever the pageProps are and include _nextI18Next as well.

@gazs
Copy link

gazs commented Sep 12, 2022

extend SSRConfig to allow whatever the pageProps are and include _nextI18Next as well.

pageProps is {} and extending it is essentially what the existing code does as far as I understand. however it fails because the Validator type expects a {} -- unsure where that comes from so far

@Zerebokep
Copy link

Stumbled about the same problem using react-query with appWithTranslation. react-query requires a dehydratedState field in pageProps, extending pageProps causes the error described.

@renadr
Copy link

renadr commented Sep 14, 2022

I have the same issue here. Is there a way to solve this problem locally?

@matchatype
Copy link
Author

I'm sorry, I don't time to help right now, but I guess you can trick TS with the following:

export default appWithTranslation<never>(App)

@ebrahimhassan121
Copy link

you can use this till they fix this bug
export default appWithTranslation(MyApp) as FC

@aziaziazi
Copy link

you can use this till they fix this bug export default appWithTranslation(MyApp) as FC

Thanks Ebrahim, worked for me with a little tweak: export default appWithTranslation(MyApp as FC)

@wjpg
Copy link

wjpg commented Sep 27, 2022

Is declaring a PageProps type which extends SSRConfig not an appropriate solution?

type PageProps = SSRConfig & Record<string, any>
<AppProps<PageProps>>

@oddsund
Copy link
Contributor

oddsund commented Oct 11, 2022

@gazs I don't think you want to do that. What you want is extend SSRConfig to allow whatever the pageProps are and include _nextI18Next as well.

As I see it, the PR is actually correct. _nextI18Next is nullable, as it may or may not be provided in each page, depending on if the page calls serverSideTranslations. Looking at the code for appWithTranslation, _nextI18Next is even checked for null/undefined. Also, I would say that _nextI18Next is an internal library type which the consumer shouldn't need to care about when calling appWithTranslation.

So #1948 would fix this. It can even include some cleanup in the function, as there are a few redundant if-checks.

Ref the "extending with what pageProps are" solution; is it even possible in Typescript as of today? Wouldn't that be a higher kind type, which isn't implemented? Ref microsoft/TypeScript#1213

Also, extending the type would still require the caller to send in the SSRConfig, which is not expected.

Another workaround:

const MyApp = ({Component, pageProps}: AppProps<YourType & SSRConfig>) => (

@stale
Copy link

stale bot commented Oct 19, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Oct 19, 2022
@Zerebokep
Copy link

stale bump

@adrai
Copy link
Member

adrai commented Oct 25, 2022

a new major version will be published as soon as -> #1966

@emrysal
Copy link

emrysal commented Nov 5, 2022

@adrai the work done (amazing work by the way, just read up on all the activity over the last month on this project) concluded 9 days ago - is the v13.0.0 tag imminent?

@adrai
Copy link
Member

adrai commented Nov 5, 2022

@adrai the work done (amazing work by the way, just read up on all the activity over the last month on this project) concluded 9 days ago - is the v13.0.0 tag imminent?

Just a TypeScript topic needs to be done and maybe another package optimization... then v13 will be released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
10 participants