fix: type plugin API against Payload shapes instead of any#3
Open
jhb-dev wants to merge 2 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.
Summary
Implements plan 012 (Option A — type-only Payload dependency) and a follow-up naming cleanup. No runtime behavior change.
fix:— type the plugin API against Payload's own shapeseslint-disable @typescript-eslint/no-explicit-anyheaders insrc/plugin/*.payloadadded as an optionalpeerDependency(^3.0.0) + pinned devDependency (3.84.1, matching the example app). Imports are type-only — nothing is added to the runtime bundle.index.ts/schemaApi.tsnow use realConfig,SanitizedConfig,Payload,PayloadRequest,Block, and the sanitized config types.contentCliPluginis(config: Config) => Config; the schema-API functions take realPayloadRequest/Block. Consumers get type-checking + autocomplete.fields.tstakesField[]/Record<string, Block>publicly and reads each field through a documented internalFieldView(nestedfields/tabs/blockskeep their real Payload types so recursion stays checked).lexical.tsstays structural —RichTextField.editoris a payload-core type, so@payloadcms/richtext-lexicalis never imported; the editor walk usesunknown+ guards. Apps without the lexical package are unaffected.tsc; kept the strict signatures clean in the IDE via a typedmockReqreturn and thin loosened wrappers over the imported functions.refactor:— replace non-descriptive short variable namesRenamed abbreviations like
ep,c,cs,op,val, and single-letter callback params (f,s,b,l,o,n) to meaningful names acrosssrcand tests. Kept conventions (err/efor errors,i/jloops,a, bsort comparators,id,ms,rl).Known cost
The published
.d.tsnow references Payload's type names, so a future Payload major reshapingField/Config/PayloadRequestcould surface a type error for consumers on that major until a compatible release ships.Verification
pnpm typecheck✅pnpm lint(0 warnings) ✅pnpm format:check✅pnpm test— 304 passed, 40 skipped (integration suite is env-gated on a running seeded example app)