Skip to content

Conversation

@Golenspade
Copy link

fix(types): apply AppType to top-level App props instead of pageProps

Problem
AppType incorrectly flowed T into AppPropsType's PageProps position, making T appear under props.pageProps rather than as top-level props (see #42846).

Fix

  • Intersect T with top-level component props and AppInitialProps
  • Keep AppPropsType's PageProps generic independent of T
  • Use unknown for PageProps to avoid accidental property access through any

Validation

  • Added a minimal tsc test (test/types/apptype-custom-props/app-type.test.ts)
    • Asserts props.foo exists at top-level
    • Asserts props.pageProps.foo does not exist (@ts-expect-error)
  • Types-only change, no runtime impact

Closes: #42846

Problem: The generic T on AppType was propagated to AppPropsType's PageProps,
causing T to appear under props.pageProps rather than top-level props.

Fix: Intersect T with the top-level component props & AppInitialProps,
and keep PageProps generic independent.

Adds a minimal tsc test to prevent regressions.

Closes: vercel#42846
… for pageProps

- Apply T to top-level App props instead of pageProps
- Use unknown (not any) for AppPropsType PageProps to prevent accidental property access
- Add minimal tsc test and tsconfig to validate semantics locally

Refs: vercel#42846
@ijjk
Copy link
Member

ijjk commented Oct 24, 2025

Allow CI Workflow Run

  • approve CI run for commit: e493ac9

Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer

@Golenspade
Copy link
Author

Additional context and validation details:

  • Rationale: AppType<T> incorrectly funneled T into AppPropsType's PageProps, so T appeared under props.pageProps instead of as top-level props. This aligns with Parameter on AppType is used incorrectly #42846's repro and with the historical AppPropsType<Router, PageProps> shape.

  • Fix summary: Intersect T with top-level component props and with AppInitialProps. Keep PageProps independent (set to unknown), preventing accidental property access via any.

  • Minimal tsc test (added): test/types/apptype-custom-props/app-type.test.ts

    • Ensures props.foo exists on the top-level
    • Ensures props.pageProps.foo is flagged (@ts-expect-error)
  • Local validation steps (types-only):

    1. Build only what's needed for d.ts: pnpm -F @next/font build then pnpm -F next types
    2. Run the focused test: ./node_modules/.bin/tsc -p test/types/apptype-custom-props/tsconfig.json

This is a type-only change and has no runtime impact.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parameter on AppType is used incorrectly

2 participants