refactor(non-verbal): eliminate parallel TS projection (TODO.figures/19 Option A)#74
Merged
Merged
Conversation
…19 Option A)
Bridges now return glossarist-js class instances (new Figure/Table/Formula/
FigureImage) instead of plain {$kind: 'figure', ...} literals. Components
narrow via instanceof and property access; the parallel TS projection in
adapters/non-verbal/types.ts is removed.
Slimmed types.ts to consumer-only types:
- LocalizedString, NonVerbalKind, FigureImageFormat, FigureImageRole
- NonVerbalSource* (wire shape for source-bridge parsing)
- TableFormat, TableContent, FormulaNotation (validated string unions)
- NonVerbRepV3 + NonVerbRepImage (local view until upstream .d.ts lands)
- NonVerbalReference (inline mention routing)
Removed (now sourced from glossarist):
- Figure, Table, Formula, FigureImage, NonVerbalEntity, NonVerbalEntityBase
Component updates:
- FigureImages accepts ImageLike = FigureImage | NonVerbRepImage for dual
compatibility with class instances (Figure) and plain objects (NonVerbRep).
- Props accept T | null throughout (upstream convention) instead of T | undefined.
- NonVerbalSources now takes ConceptSource[] directly; asCitation shim removed
since src.origin is already Citation | null in upstream.
- TableDisplay casts table.content to consumer's TableContent union.
- FormulaDisplay casts table.notation to FormulaNotation.
Added src/adapters/non-verbal/glossarist-augment.d.ts as a temporary module
augmentation. Upstream's published .d.ts (v0.4.2) re-exports Figure/Table/
Formula from index.d.ts but the underlying models/index.d.ts declares none
of them, so TypeScript silently resolves consumer imports to any. The local
augmentation restores type safety until PR glossarist/glossarist-js#31 ships.
vue-tsc --noEmit: 0 errors. npm test: 797 passed, 1 skipped.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes TODO.figures/19 Step 7 Option A.
What
Removes the parallel TypeScript projection of the non-verbal hierarchy.
Bridges now return glossarist-js class instances (
new Figure(...),new Table(...),new Formula(...),new FigureImage(...)) instead ofplain
{ \$kind: 'figure', ... }literals, and components narrow viainstanceof / property access against the upstream classes.
Why
The consumer's
adapters/non-verbal/types.tspreviously redeclared everyclass shape as a TS interface — a parallel projection of the upstream model.
Every shape change in glossarist-js required a corresponding edit here, and
the two definitions could silently drift. With this refactor the upstream
classes become the single source of truth at the type layer; this repo only
owns what is genuinely consumer-side (wire shapes parsed by the bridges,
plus the local string-union refinements).
Slimmed types.ts to consumer-only types
Kept:
LocalizedString,NonVerbalKind— routing/anchor/mention discriminatorFigureImageFormat,FigureImageRole,TableFormat,FormulaNotation—validated string unions the bridges check at parse time
NonVerbalSource*— wire shape for JSON-LD source entriesTableContent— discriminated union the TableDisplay component switches onNonVerbRepV3,NonVerbRepImage— local view of NonVerbRep's V3 runtimeshape (upstream
.d.tsstill pre-V3, see chore(types): declare NonVerbal classes in models/index.d.ts glossarist-js#31)NonVerbalReference— inline mention routing shapeRemoved (sourced from
glossarist):Figure,Table,Formula,FigureImageNonVerbalEntity,NonVerbalEntityBaseComponent updates
FigureImagesacceptsImageLike = FigureImage | NonVerbRepImageso thesame component works for class instances (Figure) and plain objects
(NonVerbRep). Nullable-safe accessors (
imgSrc,imgFormat,imgRole)paper over the
T | nullupstream convention.T | nullthroughout (upstream convention) instead ofT | undefined. Resolvers receive?? undefinedat the call site.NonVerbalSourcestakes upstreamConceptSource[]directly. The oldasCitationshim is gone —src.originis alreadyCitation | null.TableDisplaycaststable.contentto the consumer'sTableContentunion. Upstream keeps it as
Record<string, unknown>because thestructured/markup split is a consumer concern.
FormulaDisplaycastsformula.notationtoFormulaNotation.Temporary module augmentation
Added
src/adapters/non-verbal/glossarist-augment.d.ts. Upstream'spublished
.d.ts(v0.4.2) re-exportsFigure/Table/Formulafromindex.d.ts, but the underlyingmodels/index.d.tsdeclares none of them,so TypeScript silently resolves consumer imports to
any. The localaugmentation restores type safety until PR glossarist/glossarist-js#31
ships in v0.4.3+. Deletion marker is in the file header.
Verification
npx vue-tsc --noEmit— 0 errorsnpm test— 797 passed, 1 skippednpm run check:scripts— syntax OK on 14 files