fix(next): support satisfies metadata warning#95686
Open
BlackishGreen33 wants to merge 3 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #84159.
Description
The Next.js TypeScript plugin currently warns that a static
metadataexport has noMetadatatype when the export uses TypeScript'ssatisfiesoperator:This is a false warning.
satisfies Metadataalready checks the object against the Next.jsMetadatatype while preserving the more specific inferred type of its fields. For example, code that later readsmetadata.titlecan keep its inferredstringtype instead of being widened to the optionalMetadata['title']type.This PR updates the existing
hasType()check to recognize a TypeScriptSatisfiesExpressioninitializer. The plugin now treats both supported export forms as typed:export const metadata = ... satisfies MetadatametadataThe check uses the TypeScript AST and does not rely on source-text matching. Existing behavior is unchanged for metadata exports with no type information: they still receive the current warning. This change only affects the TypeScript plugin diagnostic and does not change runtime metadata handling.
Regression fixtures cover
page.tsxandlayout.tsxfor both inline and separate exports. The existing no-type cases remain in the same test suite to verify that the warning is still reported when appropriate.How did you test your changes?
Passed locally:
pnpm test-dev-turbo test/development/typescript-plugin/metadata/warn-no-type.test.tspnpm --filter=next typespnpm --filter=next buildgit diff --checkThe focused test first reproduced the incorrect diagnostic for the new
satisfies Metadatafixtures, then passed after the AST check was added.PR Checklist
Fixes #84159page.tsxandlayout.tsx