Commit 2d6be5a
authored
refactor(superdoc): convert core/types/index.js to TypeScript (SD-2869) (#3052)
* refactor(superdoc): convert core/types/index.js to TypeScript (SD-2869)
Replaces 769 lines of JSDoc @typedef declarations with native TS
interfaces, type aliases, and re-exports. Each public name is preserved
verbatim (Config, Modules, FindReplace*, PasswordPrompt*, Surface*,
ContextMenu*, Document, User, etc.) so consumers that import from
'superdoc/types' or via the auto-derived assertion list see the same
shape.
Why TS instead of JSDoc:
The drift class SD-2863 catches lives in implementations that consume
the JSDoc typedefs. The typedef file itself was unchecked: a typedef
that referenced an undefined name silently shipped as `any`. Native
TypeScript declarations are checked by the compiler at every import
site, so the typedef-side cannot drift from the implementation it
describes.
Surface preservation:
- All 50+ exported names retained.
- Optional vs required field flags retained.
- Generic typedefs (SurfaceOutcome, SurfaceHandle) keep `<T = unknown>`.
- Nested @Property declarations inlined as nested object types rather
than promoted to new named interfaces, to keep the public surface
byte-equivalent.
- JSDoc `Object` becomes TS `object` (lowercase) which matches the
resolved type consumers already saw.
- Re-exported types (Editor, StoryLocator, BookmarkAddress, etc.)
emerge from the same `@superdoc/super-editor` module under the same
names.
Verified: pnpm --filter superdoc run check:jsdoc passes (3 gated files
clean), the consumer-typecheck matrix passes 27/27, and the postbuild
declaration audit reports no FAIL findings.
* test(consumer-typecheck): pin Modules pass-through openness (SD-2869)
The SD-2869 review pass found the JSDoc → TS conversion silently
narrowed Modules.comments, Modules.toolbar, Modules.ai, Modules.pdf,
and Modules.links into closed object literals. The runtime spreads
each module config into downstream stores via `...moduleConfig`, so
extra keys are forwarded; closed types reject them with excess-property
errors. Three concrete examples surfaced in review:
- Modules.comments rejected useInternalExternalComments and
suppressInternalExternalComments (read at SuperDoc.js:561).
- Modules.toolbar rejected pagination, mode, and other forwarded
SuperToolbar options.
- onAwarenessUpdate.states was narrowed from JSDoc Array (= any[])
to unknown[], breaking handlers that read state.user.id.
The previous commit fixed each of these. This commit gates them so the
same class of regression cannot reach customers again — a future PR
that re-narrows the modules shapes or the awareness payload fails
typecheck-matrix on PR-time CI.
Constructor input is typed via ConstructorParameters<typeof SuperDoc>
because Config / Modules / FindReplaceConfig / PasswordPromptConfig
are not yet exported from the public superdoc surface. That export
gap is itself a real customer-facing issue and is filed as a separate
follow-up.1 parent 66f2c51 commit 2d6be5a
4 files changed
Lines changed: 1550 additions & 778 deletions
File tree
- packages/superdoc/src/core/types
- tests/consumer-typecheck
- src
0 commit comments