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
9df7df13
Unverified
Commit
9df7df13
authored
Feb 24, 2023
by
Balázs Orbán
Committed by
GitHub
Feb 24, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(ts): correctly augment `next` when `typedRoutes: true` (#46332)
parent
8d83d85e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
4 deletions
+15
-4
next-types-plugin.ts
packages/next/src/build/webpack/plugins/next-types-plugin.ts
+9
-4
layout.tsx
test/integration/app-types/src/app/layout.tsx
+6
-0
No files found.
packages/next/src/build/webpack/plugins/next-types-plugin.ts
View file @
9df7df13
...
@@ -123,12 +123,11 @@ const edgeRouteTypes: string[] = []
...
@@ -123,12 +123,11 @@ const edgeRouteTypes: string[] = []
export
const
pageFiles
=
new
Set
<
string
>
()
export
const
pageFiles
=
new
Set
<
string
>
()
function
createRouteDefinitions
()
{
function
createRouteDefinitions
(
originalNextModule
:
string
)
{
const
fallback
=
const
fallback
=
!
edgeRouteTypes
.
length
&&
!
nodeRouteTypes
.
length
?
'string'
:
''
!
edgeRouteTypes
.
length
&&
!
nodeRouteTypes
.
length
?
'string'
:
''
return
`
return
`type SearchOrHash = \`?\${string}\` | \`#\${string}\`
type SearchOrHash = \`?\${string}\` | \`#\${string}\`
type Suffix = '' | SearchOrHash
type Suffix = '' | SearchOrHash
type SafeSlug<S extends string> =
type SafeSlug<S extends string> =
...
@@ -187,6 +186,7 @@ declare module 'next/link' {
...
@@ -187,6 +186,7 @@ declare module 'next/link' {
}
}
declare module 'next' {
declare module 'next' {
${
originalNextModule
.
replaceAll
(
'../dist'
,
'next/dist'
)}
export { Route }
export { Route }
}`
}`
}
}
...
@@ -383,6 +383,11 @@ export class NextTypesPlugin {
...
@@ -383,6 +383,11 @@ export class NextTypesPlugin {
await
Promise
.
all
(
promises
)
await
Promise
.
all
(
promises
)
if
(
this
.
typedRoutes
)
{
if
(
this
.
typedRoutes
)
{
const
originalNextModule
=
await
fs
.
readFile
(
path
.
join
(
__dirname
,
'../../../../types/index.d.ts'
),
'utf-8'
)
pageFiles
.
forEach
((
file
)
=>
{
pageFiles
.
forEach
((
file
)
=>
{
this
.
collectPage
(
file
)
this
.
collectPage
(
file
)
})
})
...
@@ -391,7 +396,7 @@ export class NextTypesPlugin {
...
@@ -391,7 +396,7 @@ export class NextTypesPlugin {
const
assetPath
=
const
assetPath
=
assetDirRelative
+
'/'
+
linkTypePath
.
replace
(
/
\\
/g
,
'/'
)
assetDirRelative
+
'/'
+
linkTypePath
.
replace
(
/
\\
/g
,
'/'
)
assets
[
assetPath
]
=
new
sources
.
RawSource
(
assets
[
assetPath
]
=
new
sources
.
RawSource
(
createRouteDefinitions
()
createRouteDefinitions
(
originalNextModule
)
)
as
unknown
as
webpack
.
sources
.
RawSource
)
as
unknown
as
webpack
.
sources
.
RawSource
}
}
...
...
test/integration/app-types/src/app/layout.tsx
View file @
9df7df13
import
{
Metadata
}
from
'next'
export
const
meta
:
Metadata
=
{
title
:
'My App'
,
}
export
default
function
Root
({
children
}:
{
children
:
React
.
ReactNode
})
{
export
default
function
Root
({
children
}:
{
children
:
React
.
ReactNode
})
{
return
(
return
(
<
html
>
<
html
>
...
...
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