Skip to content

Commit e204a30

Browse files
committed
fix: ts language server rule metadata should allow null (#74704)
1 parent 7666d2e commit e204a30

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

packages/next/src/server/typescript/rules/metadata.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import {
99

1010
import type tsModule from 'typescript/lib/tsserverlibrary'
1111

12-
const TYPE_ANOTATION = ': Metadata'
13-
const TYPE_ANOTATION_ASYNC = ': Promise<Metadata>'
12+
const TYPE_ANNOTATION = ': Metadata | null'
13+
const TYPE_ANNOTATION_ASYNC = ': Promise<Metadata | null>'
1414
const TYPE_IMPORT = `\n\nimport type { Metadata } from 'next'`
1515

1616
// Find the `export const metadata = ...` node.
@@ -152,7 +152,7 @@ function updateVirtualFileWithType(
152152
const source = getSource(fileName)
153153
if (!source) return
154154

155-
// We annotate with the type in a vritual language service
155+
// We annotate with the type in a virtual language service
156156
const sourceText = source.getFullText()
157157
let nodeEnd: number
158158
let annotation: string
@@ -164,13 +164,13 @@ function updateVirtualFileWithType(
164164
const isAsync = node.modifiers?.some(
165165
(m) => m.kind === ts.SyntaxKind.AsyncKeyword
166166
)
167-
annotation = isAsync ? TYPE_ANOTATION_ASYNC : TYPE_ANOTATION
167+
annotation = isAsync ? TYPE_ANNOTATION_ASYNC : TYPE_ANNOTATION
168168
} else {
169169
return
170170
}
171171
} else {
172172
nodeEnd = node.name.getFullStart() + node.name.getFullWidth()
173-
annotation = TYPE_ANOTATION
173+
annotation = TYPE_ANNOTATION
174174
}
175175

176176
const newSource =
@@ -234,7 +234,7 @@ const metadata = {
234234

235235
const ts = getTs()
236236

237-
// We annotate with the type in a vritual language service
237+
// We annotate with the type in a virtual language service
238238
const pos = updateVirtualFileWithType(fileName, node)
239239
if (pos === undefined) return prior
240240

@@ -335,7 +335,7 @@ const metadata = {
335335
if (node.name?.getText() === 'generateMetadata') {
336336
if (isTyped(node)) return []
337337

338-
// We annotate with the type in a vritual language service
338+
// We annotate with the type in a virtual language service
339339
const pos = updateVirtualFileWithType(fileName, node, true)
340340
if (!pos) return []
341341

@@ -346,7 +346,7 @@ const metadata = {
346346
if (declaration.name.getText() === 'metadata') {
347347
if (isTyped(declaration)) break
348348

349-
// We annotate with the type in a vritual language service
349+
// We annotate with the type in a virtual language service
350350
const pos = updateVirtualFileWithType(fileName, declaration)
351351
if (!pos) break
352352

@@ -409,7 +409,7 @@ const metadata = {
409409
declaration.getSourceFile().fileName
410410
const isSameFile = declarationFileName === fileName
411411

412-
// We annotate with the type in a vritual language service
412+
// We annotate with the type in a virtual language service
413413
const pos = updateVirtualFileWithType(
414414
declarationFileName,
415415
declaration
@@ -461,7 +461,7 @@ const metadata = {
461461
if (!node) return
462462
if (isTyped(node)) return
463463

464-
// We annotate with the type in a vritual language service
464+
// We annotate with the type in a virtual language service
465465
const pos = updateVirtualFileWithType(fileName, node)
466466
if (pos === undefined) return
467467

@@ -485,7 +485,7 @@ const metadata = {
485485
if (!node) return
486486
if (isTyped(node)) return
487487

488-
// We annotate with the type in a vritual language service
488+
// We annotate with the type in a virtual language service
489489
const pos = updateVirtualFileWithType(fileName, node)
490490
if (pos === undefined) return
491491

@@ -500,7 +500,7 @@ const metadata = {
500500
if (!node) return
501501
if (isTyped(node)) return
502502
if (!isPositionInsideNode(position, node)) return
503-
// We annotate with the type in a vritual language service
503+
// We annotate with the type in a virtual language service
504504
const pos = updateVirtualFileWithType(fileName, node)
505505
if (pos === undefined) return
506506
const { languageService } = getProxiedLanguageService()

0 commit comments

Comments
 (0)