Commit 0d1d8b8
authored
refactor(superdoc): tighten @param {Object} on three callback methods (SD-2867 phase B) (#3061)
* refactor(superdoc): type createSuperdocVueApp return shape (SD-2867 phase B)
`createSuperdocVueApp()` returned `Object` per its JSDoc, so the five
fields SuperDoc.js destructures from the call (`app`, `pinia`,
`superdocStore`, `commentsStore`, `highContrastModeStore`) all
resolved to `Object` for any consumer enabling `// @ts-check`. Five
TS2339 'Property does not exist on type Object' errors at SuperDoc.js
line 464 — and inside the SD-2867 ratchet that turns each into a
gate failure.
Promotes the return type to a named `SuperdocVueAppRefs` typedef that
imports `vue.App`, `pinia.Pinia`, and the store types via
`ReturnType<typeof useSuperdocStore>` etc. The shape is internal-only
(this typedef is not on the public Modules / Config surface), so
adding it here doesn't widen the customer-visible surface.
Verified: pnpm --filter superdoc run check:jsdoc passes (3 gated files
clean); the consumer-typecheck matrix passes 31/31; the postbuild
declaration audit reports no FAIL findings; pnpm --filter superdoc
test passes 944/944.
This is groundwork for SD-2867 phase B: closing each cluster of
SuperDoc.js TS errors so the file can eventually enroll in
`CHECKED_FILES`. Five errors closed; ~133 remain across implicit-any
params, strict-null guards, and other type-not-assignable callsites.
Each cluster will land as its own focused commit.
* refactor(superdoc): add RuntimeDocument typedef for runtime doc shape (SD-2867 phase B)
The internal `doc` parameter in SuperDoc.js's private methods (#applyDocumentMode,
#attachExternalCollaboration, etc.) is shaped differently from the
public `Document` interface: SuperDoc attaches a runtime `role`,
`getEditor()`, and `getPresentationEditor()` to each entry during
init. Today those methods are typed `@param {Object} doc`, so any
attempt to enable `// @ts-check` on SuperDoc.js fails with TS2339
errors at every `doc.getEditor()` / `doc.getPresentationEditor()` /
`doc.role` access (~10 sites).
Adds a `RuntimeDocument` typedef in core/types/index.ts that extends
the public `Document` with the runtime-attached fields. Updates
#applyDocumentMode's `@param {Object} doc` to `@param {RuntimeDocument}
doc` as the first call site to migrate.
The typedef is internal-only and not on the public superdoc surface
(not in the public typedef block of packages/superdoc/src/index.js),
so consumers cannot import or pass these fields from outside.
This is groundwork: subsequent SD-2867 phase B PRs will migrate the
remaining `@param {Object} doc` sites and then enable @ts-check on the
methods involved.
Verified: pnpm --filter superdoc run check:jsdoc passes (3 gated files
clean); consumer matrix passes 31/31; declaration audit reports no
FAIL findings; published .d.ts surface unchanged (RuntimeDocument is
not re-exported from the public superdoc entry).
* refactor(superdoc): type #initCollaboration param as Modules (SD-2867 phase B)
#initCollaboration's @param was typed `Object`, so any consumer that
enables `// @ts-check` on SuperDoc.js fails at every destructure of
the function's parameter (`{ collaboration, comments }`) and at
every read of `collaborationModuleConfig.{ydoc,provider}` and
`commentsConfig.*`. Two TS2339s on line 519, plus all the downstream
property accesses up to line 605.
The actual call site at line 295 passes `this.config.modules`, so
the right shape is `Modules` (already publicly exported). Tightens
the @param to `Modules` and the @returns to `Promise<Document[] |
undefined>` (which is what the function actually returns; the value
is informational, not consumed by the caller).
Verified locally: with `// @ts-check` enabled on SuperDoc.js,
`#initCollaboration`'s body (lines 519-605) is fully type-clean.
The remaining error at line 606 is a downstream callsite (passing
`User | undefined` to a function expecting `Object`) and belongs to
the next phase B cluster, not this one.
This is groundwork; SuperDoc.js does not enroll under the gate yet.
Verified: pnpm --filter superdoc run check:jsdoc passes (3 gated
files clean); consumer matrix passes 31/31; declaration audit
reports no FAIL findings; published .d.ts surface unchanged.
* refactor(superdoc): tighten @param {Object} on three callback methods (SD-2867 phase B)
Three private/public callback methods on SuperDoc had `@param {Object}`
JSDoc that masked their actual contract:
- addSharedUser(user) — typed as Object; actually expects User
(the function reads u.email, which is a User field).
- onContentError({ error, editor }) — typed as Object; actually
expects an Error/Editor pair forwarded to config.onContentError.
- canPerformPermission({ permission, role, isInternal, comment,
trackedChange }) — typed as Object; the params are read at the
body and forwarded into the permissions resolver chain. Promoted
to a structural typedef with permission/role/isInternal/comment/
trackedChange optional (the function defaults `= {}` and treats
missing permission as a no-op via the early `if (!permission)
return false` guard).
Skipped goToSearchResult: the upstream `commands.goToSearchResult`
expects a private `SearchMatch` shape (id/from/to/text) that is
not on the public surface yet. Tightening that requires either
exporting SearchMatch publicly or asserting at the call site;
deferring to a separate follow-up. Left a comment on the JSDoc
documenting the deferral.
This is groundwork for SD-2867 phase B's gate enrollment of
SuperDoc.js. Each subsequent PR closes one cluster.
Verified: pnpm --filter superdoc run check:jsdoc passes (3 gated
files clean); consumer matrix passes 31/31; declaration audit
reports no FAIL findings; published .d.ts surface unchanged.1 parent 81337ac commit 0d1d8b8
3 files changed
Lines changed: 85 additions & 11 deletions
File tree
- packages/superdoc/src/core
- tests/consumer-typecheck
- src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
960 | 960 | | |
961 | 961 | | |
962 | 962 | | |
963 | | - | |
| 963 | + | |
964 | 964 | | |
965 | 965 | | |
966 | 966 | | |
| |||
979 | 979 | | |
980 | 980 | | |
981 | 981 | | |
982 | | - | |
983 | | - | |
984 | | - | |
| 982 | + | |
985 | 983 | | |
986 | 984 | | |
987 | 985 | | |
| |||
1078 | 1076 | | |
1079 | 1077 | | |
1080 | 1078 | | |
1081 | | - | |
1082 | | - | |
1083 | | - | |
1084 | | - | |
1085 | | - | |
1086 | | - | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + | |
1087 | 1092 | | |
1088 | 1093 | | |
1089 | 1094 | | |
| |||
1436 | 1441 | | |
1437 | 1442 | | |
1438 | 1443 | | |
1439 | | - | |
| 1444 | + | |
1440 | 1445 | | |
1441 | 1446 | | |
1442 | 1447 | | |
| |||
Lines changed: 45 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
425 | 425 | | |
426 | 426 | | |
427 | 427 | | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
428 | 452 | | |
429 | 453 | | |
430 | 454 | | |
| |||
0 commit comments