Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
6ae1e1b3
Unverified
Commit
6ae1e1b3
authored
Jan 06, 2026
by
Sebastian "Sebbie" Silbermann
Committed by
GitHub
Jan 06, 2026
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[strict-route-types] Typecheck App Router page props (#87386)
parent
5cddef4f
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
78 additions
and
36 deletions
+78
-36
typegen.ts
packages/next/src/server/lib/router-utils/typegen.ts
+4
-3
page.tsx
...e/app-dir/cache-components/app/cases/full_cached/page.tsx
+1
-1
page.tsx
...ot-found-with-pages-i18n/app/app-dir/[[...slug]]/page.tsx
+2
-2
page.tsx
...tion/app/catchall/@interception2/(.)[...dynamic]/page.tsx
+1
-1
page.tsx
...el-routes-revalidation/app/catchall/[...dynamic]/page.tsx
+1
-1
page.tsx
...pp-dir/revalidatetag-rsc/app/revalidate_via_page/page.tsx
+2
-2
page.tsx
...ent-cache/client-params/app/[category]/[product]/page.tsx
+2
-2
page.tsx
.../client-params/app/client-page-with-search-param/page.tsx
+6
-2
typed-routes-validator.test.ts
...dir/typed-routes-validator/typed-routes-validator.test.ts
+44
-10
page.tsx
.../e2e/app-dir/use-cache-private/app/search-params/page.tsx
+1
-1
page.tsx
...e2e/app-dir/use-cache/app/(dynamic)/complex-args/page.tsx
+2
-2
page.tsx
...e/app-dir/use-cache/app/(dynamic)/custom-handler/page.tsx
+2
-2
with-slug.tsx
.../app-dir/use-cache/app/(dynamic)/hoc/[slug]/with-slug.tsx
+6
-3
page.tsx
test/e2e/app-dir/use-cache/app/(dynamic)/page.tsx
+2
-2
page.tsx
...ir/build-output-ssg-bailout/app/ssg-bailout/[id]/page.tsx
+1
-1
types-gen-nounuselocal.test.ts
...dir/types-gen-nounuselocal/types-gen-nounuselocal.test.ts
+1
-1
No files found.
packages/next/src/server/lib/router-utils/typegen.ts
View file @
6ae1e1b3
...
...
@@ -739,14 +739,14 @@ export function generateValidatorFileStrict(
if
(
appPageValidations
)
{
typeDefinitions
+=
`type AppPageConfig<Route extends AppRoutes = AppRoutes> = {
default: React.ComponentType<
{ params: Promise<ParamMap[Route]> } & any> | ((props: { params: Promise<ParamMap[Route]> } & any
) => React.ReactNode | Promise<React.ReactNode> | never | void | Promise<void>)
default: React.ComponentType<
PageProps<Route>> | ((props: PageProps<Route>
) => React.ReactNode | Promise<React.ReactNode> | never | void | Promise<void>)
generateStaticParams?: (props: { params: ParamMap[Route] }) => Promise<any[]> | any[]
generateMetadata?: (
props:
{ params: Promise<ParamMap[Route]> } & any
,
props:
PageProps<Route>
,
parent: ResolvingMetadata
) => Promise<any> | any
generateViewport?: (
props:
{ params: Promise<ParamMap[Route]> } & any
,
props:
PageProps<Route>
,
parent: ResolvingViewport
) => Promise<any> | any
metadata?: any
...
...
@@ -994,6 +994,7 @@ export function generateRouteTypesFileStrict(
// Build export statement based on what's actually generated
const
routeExports
=
[
'AppRoutes'
,
'PageProps'
,
'PageRoutes'
,
'LayoutRoutes'
,
'RedirectRoutes'
,
...
...
test/e2e/app-dir/cache-components/app/cases/full_cached/page.tsx
View file @
6ae1e1b3
...
...
@@ -5,7 +5,7 @@ import { getSentinelValue } from '../../getSentinelValue'
export
default
async
function
Page
({
searchParams
:
_unused
,
}:
{
searchParams
:
Promise
<
{
n
:
string
}
>
searchParams
:
Promise
<
Record
<
string
,
string
|
string
[]
|
undefined
>
>
})
{
return
(
<>
...
...
test/e2e/app-dir/not-found-with-pages-i18n/app/app-dir/[[...slug]]/page.tsx
View file @
6ae1e1b3
...
...
@@ -22,10 +22,10 @@ async function validateSlug(slug: string[]) {
export
default
async
function
CatchAll
({
params
,
}:
{
params
:
Promise
<
{
slug
:
string
[]
}
>
params
:
Promise
<
{
slug
?
:
string
[]
}
>
})
{
const
{
slug
}
=
await
params
const
slugArray
=
Array
.
isArray
(
slug
)
?
slug
:
[
slug
]
const
slugArray
=
Array
.
isArray
(
slug
)
?
slug
:
[]
// Validate the slug
const
isValid
=
await
validateSlug
(
slugArray
)
...
...
test/e2e/app-dir/parallel-routes-revalidation/app/catchall/@interception2/(.)[...dynamic]/page.tsx
View file @
6ae1e1b3
...
...
@@ -5,7 +5,7 @@ import { useRouter } from 'next/navigation'
export
default
function
Page
({
params
,
}:
{
params
:
Promise
<
{
dynamic
:
string
}
>
params
:
Promise
<
{
dynamic
:
string
[]
}
>
})
{
const
router
=
useRouter
()
return
(
...
...
test/e2e/app-dir/parallel-routes-revalidation/app/catchall/[...dynamic]/page.tsx
View file @
6ae1e1b3
...
...
@@ -5,7 +5,7 @@ import { useRouter } from 'next/navigation'
export
default
function
Page
({
params
,
}:
{
params
:
Promise
<
{
dynamic
:
string
}
>
params
:
Promise
<
{
dynamic
:
string
[]
}
>
})
{
const
router
=
useRouter
()
return
(
...
...
test/e2e/app-dir/revalidatetag-rsc/app/revalidate_via_page/page.tsx
View file @
6ae1e1b3
...
...
@@ -6,10 +6,10 @@ import { revalidateTag } from 'next/cache'
const
RevalidateViaPage
=
async
({
searchParams
,
}:
{
searchParams
:
Promise
<
{
tag
:
string
}
>
searchParams
:
Promise
<
Record
<
string
,
string
|
string
[]
|
undefined
>
>
})
=>
{
const
{
tag
}
=
await
searchParams
revalidateTag
(
tag
,
'max'
)
revalidateTag
(
tag
as
any
,
'max'
)
return
(
<
div
className=
"flex flex-col items-center justify-center h-screen"
>
...
...
test/e2e/app-dir/segment-cache/client-params/app/[category]/[product]/page.tsx
View file @
6ae1e1b3
...
...
@@ -7,7 +7,7 @@ function Content({
searchParams
,
}:
{
params
:
Promise
<
{
product
:
string
}
>
searchParams
:
Promise
<
{
foo
:
string
}
>
searchParams
:
Promise
<
Record
<
string
,
string
|
string
[]
|
undefined
>
>
})
{
const
{
product
}
=
use
(
params
)
const
searchParamsDict
=
use
(
searchParams
)
...
...
@@ -30,7 +30,7 @@ export default function ProductPage({
searchParams
,
}:
{
params
:
Promise
<
{
product
:
string
}
>
searchParams
:
Promise
<
{
foo
:
string
}
>
searchParams
:
Promise
<
Record
<
string
,
string
|
string
[]
|
undefined
>
>
})
{
return
(
<
Suspense
fallback=
"Loading..."
>
...
...
test/e2e/app-dir/segment-cache/client-params/app/client-page-with-search-param/page.tsx
View file @
6ae1e1b3
...
...
@@ -2,7 +2,11 @@
import
{
Suspense
,
use
}
from
'react'
function
Content
({
searchParams
}:
{
searchParams
:
Promise
<
{
foo
:
string
}
>
})
{
function
Content
({
searchParams
,
}:
{
searchParams
:
Promise
<
Record
<
string
,
string
|
string
[]
|
undefined
>>
})
{
const
searchParamsDict
=
use
(
searchParams
)
let
query
=
null
...
...
@@ -20,7 +24,7 @@ function Content({ searchParams }: { searchParams: Promise<{ foo: string }> }) {
export
default
function
ClientPageWithSearchParam
({
searchParams
,
}:
{
searchParams
:
Promise
<
{
foo
:
string
}
>
searchParams
:
Promise
<
Record
<
string
,
string
|
string
[]
|
undefined
>
>
})
{
return
(
<
Suspense
fallback=
"Loading..."
>
...
...
test/e2e/app-dir/typed-routes-validator/typed-routes-validator.test.ts
View file @
6ae1e1b3
...
...
@@ -2,9 +2,10 @@ import { nextTestSetup } from 'e2e-utils'
import
{
getDistDir
}
from
'next-test-utils'
describe
(
'typed-routes-validator'
,
()
=>
{
const
{
next
,
isNextStart
,
skipped
}
=
nextTestSetup
({
const
{
next
,
isNext
Dev
,
isNext
Start
,
skipped
}
=
nextTestSetup
({
files
:
__dirname
,
skipDeployment
:
true
,
skipStart
:
true
,
})
if
(
skipped
)
{
...
...
@@ -12,6 +13,11 @@ describe('typed-routes-validator', () => {
}
it
(
'should generate route validation correctly'
,
async
()
=>
{
if
(
isNextDev
)
{
await
next
.
start
()
}
else
{
await
next
.
build
()
}
const
dts
=
await
next
.
readFile
(
`
${
getDistDir
()}
/types/validator.ts`
)
// sanity check that dev generation is working
expect
(
dts
).
toContain
(
'const handler = {} as typeof import('
)
...
...
@@ -19,7 +25,6 @@ describe('typed-routes-validator', () => {
if
(
isNextStart
)
{
it
(
'should pass type checking with valid page exports'
,
async
()
=>
{
await
next
.
stop
()
await
next
.
patchFile
(
'app/test-page.tsx'
,
`
...
...
@@ -37,7 +42,6 @@ describe('typed-routes-validator', () => {
})
it
(
'should fail type checking with invalid page exports'
,
async
()
=>
{
await
next
.
stop
()
await
next
.
patchFile
(
'app/invalid/page.tsx'
,
`
...
...
@@ -56,8 +60,44 @@ describe('typed-routes-validator', () => {
)
})
it
(
'should pass type checking with valid page props'
,
async
()
=>
{
await
next
.
patchFile
(
'app/valid/[id]/page.tsx'
,
`
export default function ValidPage(props: { params: Promise<{ id: string }> }) {
return <div>Valid Page</div>
}
`
)
const
{
exitCode
}
=
await
next
.
build
()
// clean up before assertion just in case it fails
await
next
.
deleteFile
(
'app/valid/[id]/page.tsx'
)
expect
(
exitCode
).
toBe
(
0
)
})
it
(
'should fail type checking with invalid page props'
,
async
()
=>
{
await
next
.
patchFile
(
'app/invalid/page.tsx'
,
`
export default function InvalidPage(props: { invalidProp: string }) {
return <div>Invalid Page</div>
}
`
)
const
{
exitCode
,
cliOutput
}
=
await
next
.
build
()
// clean up before assertion just in case it fails
await
next
.
deleteFile
(
'app/invalid/page.tsx'
)
expect
(
exitCode
).
toBe
(
1
)
expect
(
cliOutput
).
toMatch
(
/Type error: Type 'typeof import
\(
.*' does not satisfy the constraint 'AppPageConfig</
)
})
it
(
'should pass type checking with valid route handler exports'
,
async
()
=>
{
await
next
.
stop
()
await
next
.
patchFile
(
'app/valid/route.ts'
,
`
...
...
@@ -95,7 +135,6 @@ describe('typed-routes-validator', () => {
})
it
(
'should fail type checking with invalid route handler return type'
,
async
()
=>
{
await
next
.
stop
()
await
next
.
patchFile
(
'app/invalid/route.ts'
,
`
...
...
@@ -117,7 +156,6 @@ describe('typed-routes-validator', () => {
})
it
(
'should fail type checking with invalid route handler params'
,
async
()
=>
{
await
next
.
stop
()
await
next
.
patchFile
(
'app/invalid-2/route.ts'
,
`
...
...
@@ -139,7 +177,6 @@ describe('typed-routes-validator', () => {
})
it
(
'should pass type checking with valid layout exports'
,
async
()
=>
{
await
next
.
stop
()
await
next
.
patchFile
(
'app/test/layout.tsx'
,
`
...
...
@@ -160,7 +197,6 @@ describe('typed-routes-validator', () => {
})
it
(
'should fail type checking with invalid layout exports'
,
async
()
=>
{
await
next
.
stop
()
await
next
.
patchFile
(
'app/invalid/layout.tsx'
,
`
...
...
@@ -182,7 +218,6 @@ describe('typed-routes-validator', () => {
})
it
(
'should pass type checking with valid API route exports'
,
async
()
=>
{
await
next
.
stop
()
await
next
.
patchFile
(
'pages/api/valid-api.ts'
,
`
...
...
@@ -208,7 +243,6 @@ describe('typed-routes-validator', () => {
})
it
(
'should fail type checking with invalid API route exports'
,
async
()
=>
{
await
next
.
stop
()
await
next
.
patchFile
(
'pages/api/invalid-api.ts'
,
`
...
...
test/e2e/app-dir/use-cache-private/app/search-params/page.tsx
View file @
6ae1e1b3
export
default
async
function
Page
({
searchParams
,
}:
{
searchParams
:
Promise
<
{
[
key
:
string
]:
string
}
>
searchParams
:
Promise
<
Record
<
string
,
string
|
string
[]
|
undefined
>
>
})
{
'use cache: private'
...
...
test/e2e/app-dir/use-cache/app/(dynamic)/complex-args/page.tsx
View file @
6ae1e1b3
...
...
@@ -10,9 +10,9 @@ async function getCached({ p }) {
export
default
async
function
Page
({
searchParams
,
}:
{
searchParams
:
Promise
<
{
n
:
string
}
>
searchParams
:
Promise
<
Record
<
string
,
string
|
string
[]
|
undefined
>
>
})
{
const
n
=
parseInt
((
await
searchParams
).
n
,
16
)
const
n
=
parseInt
((
await
searchParams
).
n
as
any
,
16
)
const
p
=
Promise
.
resolve
(
new
Uint8Array
([
n
]))
return
<
p
id=
"x"
>
{
await
getCached
({
p
})
}
</
p
>
}
test/e2e/app-dir/use-cache/app/(dynamic)/custom-handler/page.tsx
View file @
6ae1e1b3
...
...
@@ -10,9 +10,9 @@ async function getCachedRandom(x: number, children: React.ReactNode) {
export
default
async
function
Page
({
searchParams
,
}:
{
searchParams
:
Promise
<
{
n
:
string
}
>
searchParams
:
Promise
<
Record
<
string
,
string
|
string
[]
|
undefined
>
>
})
{
const
n
=
+
(
await
searchParams
).
n
const
n
=
+
(
await
searchParams
).
n
!
const
values
=
await
getCachedRandom
(
n
,
<
p
id=
"r"
>
rnd
{
Math
.
random
()
}
</
p
>
// This should not invalidate the cache
...
...
test/e2e/app-dir/use-cache/app/(dynamic)/hoc/[slug]/with-slug.tsx
View file @
6ae1e1b3
export
function
withSlug
<
P
extends
{
params
:
Promise
<
{
slug
:
string
}
>
}
>
(
export
function
withSlug
(
Component
:
React
.
ComponentType
<
{
slug
:
string
}
>
):
React
.
ComponentType
<
{
params
:
Promise
<
{
slug
:
string
}
>
}
>
{
return
async
function
ComponentWithSlug
(
props
:
P
)
{
):
// TODO(NXT-127): Use ComponentType
React
.
JSXElementConstructor
<
{
params
:
Promise
<
{
slug
:
string
}
>
}
>
{
return
async
function
ComponentWithSlug
(
props
:
{
params
:
Promise
<
{
slug
:
string
}
>
})
{
const
params
=
await
props
.
params
const
slug
=
params
.
slug
...
...
test/e2e/app-dir/use-cache/app/(dynamic)/page.tsx
View file @
6ae1e1b3
...
...
@@ -13,9 +13,9 @@ async function getCachedRandom(x: number, children: React.ReactNode) {
export
default
async
function
Page
({
searchParams
,
}:
{
searchParams
:
Promise
<
{
n
:
string
}
>
searchParams
:
Promise
<
Record
<
string
,
string
|
string
[]
|
undefined
>
>
})
{
const
n
=
+
(
await
searchParams
).
n
const
n
=
+
(
await
searchParams
).
n
!
const
values
=
await
getCachedRandom
(
n
,
<
p
id=
"r"
>
rnd
{
Math
.
random
()
}
</
p
>
// This should not invalidate the cache
...
...
test/production/app-dir/build-output-ssg-bailout/app/ssg-bailout/[id]/page.tsx
View file @
6ae1e1b3
export
default
async
function
Page
({
searchParams
,
}:
{
searchParams
:
Promise
<
{
id
:
string
}
>
searchParams
:
Promise
<
Record
<
string
,
string
|
string
[]
|
undefined
>
>
})
{
const
{
id
}
=
await
searchParams
return
<
p
>
hello world
{
id
}
</
p
>
...
...
test/production/app-dir/types-gen-nounuselocal/types-gen-nounuselocal.test.ts
View file @
6ae1e1b3
...
...
@@ -55,7 +55,7 @@ describe('types-gen-nounuselocal', () => {
}
export type { AppRoutes, PageRoutes, LayoutRoutes, RedirectRoutes, RewriteRoutes, ParamMap }
export type { AppRoutes, Page
Props, Page
Routes, LayoutRoutes, RedirectRoutes, RewriteRoutes, ParamMap }
declare global {
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment