Skip to content

Commit 0ade67d

Browse files
authored
Merge pull request #3492 from superdoc-dev/caio-pizzol/SD-typecheck-coverage-drain-4
test(typecheck): drain 4 surface API obligations from public-method coverage (SD-673)
2 parents 95534e9 + ef28aef commit 0ade67d

2 files changed

Lines changed: 55 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
@@ -5,8 +5,6 @@
55
"addCommentsList:returns",
66
"canPerformPermission:parameters",
77
"canPerformPermission:returns",
8-
"closeSurface:parameters",
9-
"closeSurface:returns",
108
"export:parameters",
119
"export:returns",
1210
"exportEditorsToDOCX:parameters",
@@ -15,8 +13,6 @@
1513
"getPresentationEditorForDocument:returns",
1614
"lockSuperdoc:parameters",
1715
"lockSuperdoc:returns",
18-
"openSurface:parameters",
19-
"openSurface:returns",
2016
"removeCommentsList:returns",
2117
"save:returns",
2218
"scrollToComment:parameters",
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* Consumer typecheck: surface public APIs on `SuperDoc`.
3+
*
4+
* Locks the `openSurface` and `closeSurface` contracts (parameters
5+
* and returns) against the emitted `.d.ts` with strict identity
6+
* equality. A future migration that narrows or widens either signature
7+
* will fail the obligation diff rather than slipping past CI.
8+
*
9+
* `openSurface` is generic: `openSurface<TResult = unknown>(request)`.
10+
* `ReturnType<SuperDoc['openSurface']>` applies the `TResult = unknown`
11+
* default, so the locked return is `SurfaceHandle<unknown>`. Callers
12+
* that bind an explicit `TResult` get `SurfaceHandle<TResult>` at the
13+
* call site; this fixture asserts the default-instantiated shape on
14+
* the bare method type, which is what `Parameters` / `ReturnType`
15+
* actually see.
16+
*
17+
* Drained obligations (4):
18+
* - openSurface:parameters / openSurface:returns
19+
* - closeSurface:parameters / closeSurface:returns
20+
*/
21+
import type { SuperDoc, SurfaceHandle, SurfaceRequest } from 'superdoc';
22+
23+
type Equal<A, B> = (<T>() => T extends A ? 1 : 2) extends <T>() => T extends B ? 1 : 2 ? true : false;
24+
type AssertEqual<A, B> = Equal<A, B> extends true ? true : never;
25+
26+
declare const sd: SuperDoc;
27+
declare const request: SurfaceRequest;
28+
29+
// ─── openSurface ────────────────────────────────────────────────────
30+
// Forwards to SurfaceManager.open. Generic on TResult (default
31+
// `unknown`); the returned handle's `result` promise resolves with a
32+
// SurfaceOutcome carrying that TResult.
33+
const _openSurfaceParamsOk: AssertEqual<Parameters<SuperDoc['openSurface']>, [request: SurfaceRequest]> = true;
34+
const _openSurfaceReturnOk: AssertEqual<ReturnType<SuperDoc['openSurface']>, SurfaceHandle<unknown>> = true;
35+
const _openSurfaceHandle: SurfaceHandle<unknown> = sd.openSurface(request);
36+
void _openSurfaceHandle;
37+
38+
// Lock the generic at the call site. A future refactor that drops
39+
// `<TResult>` (e.g. inlining the default) would still satisfy the
40+
// Parameters / ReturnType assertions above, since utility-type
41+
// extraction sees the default-instantiated shape. This explicit
42+
// binding fails to compile if `TResult` stops flowing into the
43+
// returned `SurfaceHandle<TResult>`.
44+
const _typedSurfaceHandle: SurfaceHandle<{ accepted: true }> = sd.openSurface<{ accepted: true }>(request);
45+
void _typedSurfaceHandle;
46+
47+
// ─── closeSurface ───────────────────────────────────────────────────
48+
// Closes a surface by id, or the topmost surface when `id` is
49+
// omitted. Forwards to SurfaceManager.close.
50+
const _closeSurfaceParamsOk: AssertEqual<Parameters<SuperDoc['closeSurface']>, [id?: string]> = true;
51+
const _closeSurfaceReturnOk: AssertEqual<ReturnType<SuperDoc['closeSurface']>, void> = true;
52+
sd.closeSurface();
53+
sd.closeSurface('surface-id');
54+
55+
void [_openSurfaceParamsOk, _openSurfaceReturnOk, _closeSurfaceParamsOk, _closeSurfaceReturnOk];

0 commit comments

Comments
Β (0)