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

Incorrect TS type of AppTree? #8656

Closed
fwojciec opened this issue Sep 6, 2019 · 2 comments · Fixed by #8662
Closed

Incorrect TS type of AppTree? #8656

fwojciec opened this issue Sep 6, 2019 · 2 comments · Fixed by #8662
Assignees
Milestone

Comments

@fwojciec
Copy link
Contributor

fwojciec commented Sep 6, 2019

Bug report

Describe the bug

Currently the TS type for AppTree component is AppType:

export declare type AppType = NextComponentType<AppContextType, AppInitialProps, AppPropsType>

(...)

export interface NextPageContext {
    // (...)
    AppTree: AppType;
}

This seems incorrect, since this type defines Component and router as required props. As a result, it is impossible to use AppTree in getInitialProps of a page component without manually overriding the type, since there is no way to access Component and router from NextPageContext. AppTree appears to work just fine without the props defined as required -- and in fact the official with-apollo example uses AppTree in precisely this way.

To Reproduce

  1. Reproduction repo here: https://github.com/fwojciec/apptree-type-reproduction-example
  2. The relevant file is lib/apollo.tsx
  3. I'm overriding the types for AppTree in this HOC (very loosely based on the official with-apollo example) in order to make it work in TypeScript (see FixedAppTree).
  4. If you replace FixedAppTree with the original AppTree on line 56 the TS compiler will complain about missing props:
Type '{ pageProps: { apolloClient: ApolloClient<NormalizedCacheObject>; }; }' is missing the following properties from type '{ Component: NextComponentType<NextPageContext, any, {}>; router: NextRouter; }': Component, routerts(2739)

Expected behavior

The default type of AppTree should not define Component and router as required props.

System information

  • OS: macOS
  • Browser: N/A
  • Version of Next.js: 9.0.5

Additional context

  • TypeScript version: 3.6.2
@fwojciec
Copy link
Contributor Author

fwojciec commented Sep 6, 2019

Created a pull request to fix this -- though I'm not sure this is the best approach:
#8662

@ijjk ijjk closed this as completed in #8662 Sep 9, 2019
@Timer Timer modified the milestones: 9.0.x, 9.0.6 Sep 9, 2019
@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 31, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants