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
4d7d9abc
Unverified
Commit
4d7d9abc
authored
Nov 24, 2025
by
Jiachi Liu
Committed by
GitHub
Nov 24, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[ts-plugin] keep showing the types in the function body (#86273)
parent
7e093afb
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
92 additions
and
20 deletions
+92
-20
config.ts
packages/next/src/server/typescript/rules/config.ts
+60
-6
page.tsx
test/development/typescript-plugin/app/page.tsx
+1
-9
layout.tsx
...velopment/typescript-plugin/app/project/[slug]/layout.tsx
+9
-0
page.tsx
...development/typescript-plugin/app/project/[slug]/page.tsx
+13
-0
page.tsx
...-dir/typed-routes/app/(logged-in)/project/[slug]/page.tsx
+9
-0
next.config.js
test/e2e/app-dir/typed-routes/next.config.js
+0
-5
No files found.
packages/next/src/server/typescript/rules/config.ts
View file @
4d7d9abc
...
@@ -5,6 +5,7 @@ import {
...
@@ -5,6 +5,7 @@ import {
isPositionInsideNode
,
isPositionInsideNode
,
getTs
,
getTs
,
removeStringQuotes
,
removeStringQuotes
,
getTypeChecker
,
}
from
'../utils'
}
from
'../utils'
import
{
NEXT_TS_ERRORS
,
ALLOWED_EXPORTS
}
from
'../constant'
import
{
NEXT_TS_ERRORS
,
ALLOWED_EXPORTS
}
from
'../constant'
import
type
tsModule
from
'typescript/lib/tsserverlibrary'
import
type
tsModule
from
'typescript/lib/tsserverlibrary'
...
@@ -308,9 +309,49 @@ const config = {
...
@@ -308,9 +309,49 @@ const config = {
API_DOCS
[
entryConfig
].
link
,
API_DOCS
[
entryConfig
].
link
,
}
}
if
(
value
&&
isPositionInsideNode
(
position
,
value
))
{
// When the value is a flexible type (like a function), also compute its
// Hovers the value of the config
// inferred type so we can surface it alongside the docs. This is useful
const
isString
=
ts
.
isStringLiteral
(
value
)
// even when the value is considered invalid by the config validation,
// as long as it's not a direct literal export.
let
displayParts
:
tsModule
.
SymbolDisplayPart
[]
=
[]
const
typeChecker
=
getTypeChecker
()
const
isString
=
!!
value
&&
ts
.
isStringLiteral
(
value
)
const
isFunctionValue
=
!!
value
&&
!
isString
&&
(
ts
.
isArrowFunction
(
value
)
||
ts
.
isFunctionExpression
(
value
)
||
ts
.
isFunctionDeclaration
(
value
))
if
(
typeChecker
&&
value
&&
isFunctionValue
)
{
try
{
// If we're hovering the config identifier, ask for the type at the
// identifier; otherwise, ask at the value node. This makes sure
// highlighting `generateMetadata` itself also shows the inferred type.
const
typeTarget
=
isPositionInsideNode
(
position
,
name
)
?
name
:
value
const
type
=
typeChecker
.
getTypeAtLocation
(
typeTarget
)
if
(
type
)
{
const
typeString
=
typeChecker
.
typeToString
(
type
,
typeTarget
)
if
(
typeString
)
{
displayParts
=
[
{
text
:
typeString
,
kind
:
'typeName'
,
},
]
}
}
}
catch
{
// If type checking fails, continue without type info.
}
}
// For non-function values (like literals), hovering the value should show
// option-specific docs. For function-valued configs (e.g. `generateMetadata`),
// we let TypeScript handle hover anywhere in the initializer except for the
// export identifier itself.
if
(
value
&&
!
isFunctionValue
&&
isPositionInsideNode
(
position
,
value
))
{
// Hovering the value of the config
const
text
=
removeStringQuotes
(
value
.
getText
())
const
text
=
removeStringQuotes
(
value
.
getText
())
const
key
=
isString
?
`"
${
text
}
"`
:
text
const
key
=
isString
?
`"
${
text
}
"`
:
text
...
@@ -339,7 +380,8 @@ const config = {
...
@@ -339,7 +380,8 @@ const config = {
],
],
}
}
}
else
{
}
else
{
// Wrong value, display the docs link
// Wrong value: still show the docs link, and when available, the
// inferred type for non-literal (i.e. non-direct) exports.
overridden
=
{
overridden
=
{
kind
:
ts
.
ScriptElementKind
.
enumElement
,
kind
:
ts
.
ScriptElementKind
.
enumElement
,
kindModifiers
:
ts
.
ScriptElementKindModifier
.
none
,
kindModifiers
:
ts
.
ScriptElementKindModifier
.
none
,
...
@@ -347,11 +389,23 @@ const config = {
...
@@ -347,11 +389,23 @@ const config = {
start
:
value
.
getStart
(),
start
:
value
.
getStart
(),
length
:
value
.
getWidth
(),
length
:
value
.
getWidth
(),
},
},
displayParts
:
[]
,
displayParts
,
documentation
:
[
docsLink
],
documentation
:
[
docsLink
],
}
}
}
}
}
else
{
}
else
{
// For function-valued configs, if we're hovering anywhere within the
// initializer (including `async`, parameters, or the body) but not on
// the export identifier itself, don't override TypeScript's default
// hover. We only want to override when hovering the config identifier
// (e.g. `generateMetadata`), not arbitrary tokens within the function.
if
(
isFunctionValue
&&
isPositionInsideNode
(
position
,
value
)
&&
// hover is somewhere within the function initializer
!
isPositionInsideNode
(
position
,
name
)
// ...but not on the export identifier itself
)
{
return
}
// Hovers the name of the config
// Hovers the name of the config
overridden
=
{
overridden
=
{
kind
:
ts
.
ScriptElementKind
.
enumElement
,
kind
:
ts
.
ScriptElementKind
.
enumElement
,
...
@@ -360,7 +414,7 @@ const config = {
...
@@ -360,7 +414,7 @@ const config = {
start
:
name
.
getStart
(),
start
:
name
.
getStart
(),
length
:
name
.
getWidth
(),
length
:
name
.
getWidth
(),
},
},
displayParts
:
[]
,
displayParts
,
documentation
:
[
documentation
:
[
{
{
kind
:
'text'
,
kind
:
'text'
,
...
...
test/development/typescript-plugin/app/page.tsx
View file @
4d7d9abc
import
{
ClientComponent
}
from
'./client'
const
noop
=
()
=>
{}
export
default
function
Page
()
{
export
default
function
Page
()
{
return
(
return
<>
hello world
</>
<>
<
ClientComponent
unknown=
{
noop
}
unknownAction=
{
noop
}
/>
</>
)
}
}
test/development/typescript-plugin/app/project/[slug]/layout.tsx
0 → 100644
View file @
4d7d9abc
import
{
Metadata
}
from
'next'
export
default
function
Layout
({
children
}:
{
children
:
React
.
ReactNode
})
{
return
<>
{
children
}
</>
}
export
const
metadata
:
Metadata
=
{
title
:
'Project Layout'
,
}
test/development/typescript-plugin/app/project/[slug]/page.tsx
0 → 100644
View file @
4d7d9abc
export
default
async
function
Page
(
props
:
PageProps
<
'/project/[slug]'
>
)
{
const
{
slug
}
=
await
props
.
params
return
<
p
>
project
{
slug
}
</
p
>
}
export
const
generateMetadata
=
async
({
params
,
}:
PageProps
<
'/project/[slug]'
>
)
=>
{
const
{
slug
}
=
await
params
return
{
title
:
`Project
${
slug
}
`
,
}
}
test/e2e/app-dir/typed-routes/app/(logged-in)/project/[slug]/page.tsx
View file @
4d7d9abc
...
@@ -2,3 +2,12 @@ export default async function Page(props: PageProps<'/project/[slug]'>) {
...
@@ -2,3 +2,12 @@ export default async function Page(props: PageProps<'/project/[slug]'>) {
const
{
slug
}
=
await
props
.
params
const
{
slug
}
=
await
props
.
params
return
<
p
>
project
{
slug
}
</
p
>
return
<
p
>
project
{
slug
}
</
p
>
}
}
export
const
generateMetadata
=
async
({
params
,
}:
PageProps
<
'/project/[slug]'
>
)
=>
{
const
{
slug
}
=
await
params
return
{
title
:
`Project
${
slug
}
`
,
}
}
test/e2e/app-dir/typed-routes/next.config.js
View file @
4d7d9abc
...
@@ -8,11 +8,6 @@ const nextConfig = {
...
@@ -8,11 +8,6 @@ const nextConfig = {
typedRoutes
:
true
,
typedRoutes
:
true
,
async
redirects
()
{
async
redirects
()
{
return
[
return
[
{
source
:
'/project/:slug'
,
destination
:
'/project/:slug'
,
permanent
:
true
,
},
{
{
source
:
'/blog/:category/:slug*'
,
source
:
'/blog/:category/:slug*'
,
destination
:
'/posts/:category/:slug*'
,
destination
:
'/posts/:category/:slug*'
,
...
...
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