Refactor SEO Plugin Types for Enhanced Type Safety and Structured Document Handling #8123
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.
Description
This pull request refactors the SEO plugin types to introduce TypedFormDocument and TypedFormField types, enhancing the type safety and flexibility of the document objects used in the SEO generation functions (GenerateTitle, GenerateDescription, GenerateImage, and GenerateURL). By replacing the generic doc type with TypedFormDocument, we ensure that each field within the document is well-defined, predictable, and type-checked, reducing potential errors and improving developer experience when extending or maintaining these functions. This change is aimed at enhancing the robustness of the SEO plugin’s type definitions, making them more intuitive and aligned with the evolving architecture of the Payload CMS.
Primary Motivation was the fact that the doc param in the
generate
functions is not the type of the generated types from payload. It is a an object with FormField values. This is not readily apparent.This also adjusts the
Generate
function types to allow for a generic to be passed in.From
GenerateTitle = <T = any>(
To
GenerateTitle<T = any> = (
Type of change
Checklist:
Honestly for these guys I can't confirm. Im running this in GitHub codebases and from the get go before any changes I could not get a build to work. But I think this is purely the codespaces env issue.