|
| 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