Skip to content

Commit 3728071

Browse files
authored
Merge pull request #3483 from superdoc-dev/caio-pizzol/SD-typecheck-coverage-drain-2
feat(typecheck): drain 4 comment/mode obligations + flag User-type identity mismatch
2 parents 00b7883 + 868f05d commit 3728071

2 files changed

Lines changed: 58 additions & 4 deletions

File tree

β€Žtests/consumer-typecheck/public-method-coverage-debt-snapshot.jsonβ€Ž

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
"exportEditorsToDOCX:parameters",
1717
"exportEditorsToDOCX:returns",
1818
"focus:returns",
19-
"getComment:parameters",
20-
"getComment:returns",
2119
"getPresentationEditorForDocument:parameters",
2220
"getPresentationEditorForDocument:returns",
2321
"lockSuperdoc:parameters",
@@ -33,8 +31,6 @@
3331
"scrollToComment:returns",
3432
"setDisableContextMenu:parameters",
3533
"setDisableContextMenu:returns",
36-
"setDocumentMode:parameters",
37-
"setDocumentMode:returns",
3834
"setHighContrastMode:parameters",
3935
"setHighContrastMode:returns",
4036
"setLocked:parameters",
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/**
2+
* Consumer typecheck: comment + mode public APIs on `SuperDoc`.
3+
*
4+
* Drains the second batch of obligations from the public-method
5+
* coverage gate (#3481). Each assertion locks the parameter or return
6+
* shape of a method on the supported root surface, so a future
7+
* migration cannot quietly narrow or widen the contract without CI
8+
* failing on the obligation diff.
9+
*
10+
* Methods covered here (return types verified against the emitted
11+
* `.d.ts`, not inferred from intent):
12+
*
13+
* - `getComment(commentId)` β†’ `Record<string, unknown> | null`
14+
* - `setDocumentMode(type)` β†’ `void`
15+
*
16+
* `setDocumentMode` has no declared return type in source; TS infers
17+
* `void`, which the emitted `.d.ts` ships. The `void` assertion is
18+
* deliberate: it forces a future tightening that introduces a real
19+
* return value (e.g. `boolean`) to land as an intentional contract
20+
* change.
21+
*
22+
* `addSharedUser` / `removeSharedUser` obligations are intentionally
23+
* deferred (still on the debt snapshot). Their parameter and return
24+
* types reference a different `User` interface than the one
25+
* `superdoc` re-exports publicly: the methods accept the internal
26+
* `User` from `packages/superdoc/src/core/types/index.ts`, while
27+
* `import { User } from 'superdoc'` resolves to the super-editor
28+
* `User` re-exported via `src/public/index.ts`. Strict `AssertEqual<>`
29+
* fails on this identity mismatch even though the shapes are
30+
* structurally similar. The right fix is upstream β€” unify the two
31+
* User types so the public consumer surface and the method signature
32+
* match β€” not loosen the fixture assertion class. Tracked as a
33+
* separate follow-up.
34+
*/
35+
import type { DocumentMode, SuperDoc } from 'superdoc';
36+
37+
type Equal<A, B> = (<T>() => T extends A ? 1 : 2) extends <T>() => T extends B ? 1 : 2 ? true : false;
38+
type AssertEqual<A, B> = Equal<A, B> extends true ? true : never;
39+
40+
declare const sd: SuperDoc;
41+
42+
// ─── getComment ─────────────────────────────────────────────────────
43+
// Looks up a comment by id in the comments Pinia store. Returns the
44+
// raw comment record (untyped at the Pinia layer, hence
45+
// `Record<string, unknown>`) or `null` for unknown ids / no store.
46+
const _getCommentParamsOk: AssertEqual<Parameters<SuperDoc['getComment']>, [commentId: string]> = true;
47+
const _getCommentReturnOk: AssertEqual<ReturnType<SuperDoc['getComment']>, Record<string, unknown> | null> = true;
48+
const _commentValue: Record<string, unknown> | null = sd.getComment('comment-id-1');
49+
50+
// ─── setDocumentMode ────────────────────────────────────────────────
51+
// Switches the document mode. Early-returns on falsy `type` and on
52+
// pre-ready state. Return is `void`.
53+
const _setDocumentModeParamsOk: AssertEqual<Parameters<SuperDoc['setDocumentMode']>, [type: DocumentMode]> = true;
54+
const _setDocumentModeReturnOk: AssertEqual<ReturnType<SuperDoc['setDocumentMode']>, void> = true;
55+
const editingMode: DocumentMode = 'editing';
56+
sd.setDocumentMode(editingMode);
57+
58+
void [_getCommentParamsOk, _getCommentReturnOk, _commentValue, _setDocumentModeParamsOk, _setDocumentModeReturnOk];

0 commit comments

Comments
Β (0)