Skip to content

fix: type plugin API against Payload shapes instead of any#3

Open
jhb-dev wants to merge 2 commits into
mainfrom
fix/type-plugin-payload-shapes
Open

fix: type plugin API against Payload shapes instead of any#3
jhb-dev wants to merge 2 commits into
mainfrom
fix/type-plugin-payload-shapes

Conversation

@jhb-dev

@jhb-dev jhb-dev commented May 31, 2026

Copy link
Copy Markdown
Contributor

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 shapes

  • Removed all four eslint-disable @typescript-eslint/no-explicit-any headers in src/plugin/*.
  • payload added as an optional peerDependency (^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.ts now use real Config, SanitizedConfig, Payload, PayloadRequest, Block, and the sanitized config types. contentCliPlugin is (config: Config) => Config; the schema-API functions take real PayloadRequest/Block. Consumers get type-checking + autocomplete.
  • fields.ts takes Field[]/Record<string, Block> publicly and reads each field through a documented internal FieldView (nested fields/tabs/blocks keep their real Payload types so recursion stays checked).
  • lexical.ts stays structuralRichTextField.editor is a payload-core type, so @payloadcms/richtext-lexical is never imported; the editor walk uses unknown + guards. Apps without the lexical package are unaffected.
  • Tests are excluded from tsc; kept the strict signatures clean in the IDE via a typed mockReq return and thin loosened wrappers over the imported functions.

refactor: — replace non-descriptive short variable names

Renamed abbreviations like ep, c, cs, op, val, and single-letter callback params (f, s, b, l, o, n) to meaningful names across src and tests. Kept conventions (err/e for errors, i/j loops, a, b sort comparators, id, ms, rl).

Known cost

The published .d.ts now references Payload's type names, so a future Payload major reshaping Field/Config/PayloadRequest could surface a type error for consumers on that major until a compatible release ships.

Verification

  • pnpm typecheckpnpm lint (0 warnings) ✅ pnpm format:check
  • pnpm test — 304 passed, 40 skipped (integration suite is env-gated on a running seeded example app)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant