Unverified Commit 54c3107e authored by Jiwon Choi's avatar Jiwon Choi Committed by GitHub

[ts-next-plugin] warn to add correct type for metadata exports (#78254)

Follow up of https://github.com/vercel/next.js/pull/78237,
https://github.com/vercel/next.js/pull/78258

If the exports of metadata options are missing types, warn them to
import type to prevent breaking the app from invalid metadata.

The warning covers:

- `metadata` export
- `generateMetadata` export
  - as function
  - as async function
  - as arrow function
  - as async arrow function
  - as function expression
  - as async function expression
- all of the above as `export { ... }`


https://github.com/user-attachments/assets/a25f9734-0d36-4592-a6fb-71faa7c00dbd

---------
Co-authored-by: 's avatarSebastian "Sebbie" Silbermann <sebastian.silbermann@vercel.com>
parent a3b9aed6
......@@ -223,11 +223,14 @@ export const createTSPlugin: tsModule.server.PluginModuleFactory = ({
node
)
const metadataDiagnostics = isClientEntry
? metadata.getSemanticDiagnosticsForExportVariableStatementInClientEntry(
? metadata.client.getSemanticDiagnosticsForExportVariableStatement(
fileName,
node
)
: metadata.server.getSemanticDiagnosticsForExportVariableStatement(
fileName,
node
)
: []
prior.push(...diagnostics, ...metadataDiagnostics)
}
......@@ -283,11 +286,14 @@ export const createTSPlugin: tsModule.server.PluginModuleFactory = ({
// export function ...
if (isAppEntry) {
const metadataDiagnostics = isClientEntry
? metadata.getSemanticDiagnosticsForExportVariableStatementInClientEntry(
? metadata.client.getSemanticDiagnosticsForExportVariableStatement(
fileName,
node
)
: metadata.server.getSemanticDiagnosticsForExportVariableStatement(
fileName,
node
)
: []
prior.push(...metadataDiagnostics)
}
......@@ -312,11 +318,11 @@ export const createTSPlugin: tsModule.server.PluginModuleFactory = ({
// export { ... }
if (isAppEntry) {
const metadataDiagnostics = isClientEntry
? metadata.getSemanticDiagnosticsForExportDeclarationInClientEntry(
? metadata.client.getSemanticDiagnosticsForExportDeclaration(
fileName,
node
)
: metadata.getSemanticDiagnosticsForExportDeclaration(
: metadata.server.getSemanticDiagnosticsForExportDeclaration(
fileName,
node
)
......
......@@ -17,7 +17,7 @@ const errorEntry = {
const ts = getTs()
if (!isClientEntry) {
// Error components must be Client components
// Error components must be Client Components
return [
{
file: source,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment