Repository navigation
Description
Split out of #1047, which fixed the narrower LexiconOutput cast. This one is the wider design question and deliberately was not folded in.
The gap
Declarable (packages/core/src/declarable.ts:9) describes four things:
export interface Declarable {
readonly lexicon: string;
readonly entityType: string;
readonly kind?: "resource" | "property" | "output";
readonly [DECLARABLE_MARKER]: true;
}It does not describe props or attributes — the fields that carry the actual resource payload and that 10 of 11 lexicon serializers read. So every consumer that needs them reaches through an unchecked cast. In packages/core/src/discovery/entity-wire.ts alone:
253: const props = "props" in decl ? (decl as unknown as { props?: unknown }).props : undefined;
277: if ("props" in entity && (entity as unknown as { props?: unknown }).props !== undefined) {
278: wire.props = encodeValue((entity as unknown as { props: unknown }).props, entityNames);
280: if ("attributes" in entity && (entity as unknown as { attributes?: unknown }).attributes !== undefined) {
281: wire.attributes = encodeValue((entity as unknown as { attributes: unknown }).attributes, entityNames);The "props" in entity guards are doing real work — not every Declarable has props — but the payload comes back as unknown and each call site re-invents both the guard and the shape.
Why it matters more now
Before #1046 this was ordinary structural typing in a few serializers. Now the entity-wire encoder — the thing that decides what crosses a process boundary for #1045 — decides what to serialize based on untyped in checks. A resource kind carrying its payload under a differently-named field would be silently dropped rather than caught by the compiler. The 98-entry differential would catch it only if a corpus entry happens to exercise that shape.
Options
- Widen
Declarablewith optionalprops?: unknown/attributes?: unknown. Smallest change, keeps one type, but weakens the interface for the genuinely payload-less kinds (outputs, parameters) and does not give real types. - Add a
ResourceDeclarablesub-interface carryingprops/attributes, with a type guard replacing the ad-hoc"props" in xchecks. KeepsDeclarableminimal and honest, and gives one guard to maintain. More churn. - Leave it, document it. Defensible — the casts work today and structural checks are idiomatic — but then the entity-wire encoder should at least route every access through one shared helper instead of five inline casts.
Option 2 looks right, but it touches all eleven lexicons, so it needs a deliberate decision rather than an opportunistic fix.
Non-goals
- Typing
propsper resource type. The generated resource classes already do that; this is only about the base interface consumers see. - Anything about
LexiconOutput— that was refactor(core): entity-wire reads LexiconOutput internals through an unchecked cast #1047.
Acceptance
- A decision recorded between the options above, with reasoning.
- If 1 or 2: no
as unknown asforprops/attributesinentity-wire.ts, and lexicon serializers reading them through the shared type or guard. - If 3: a single shared accessor in
entity-wire.tsrather than repeated inline casts, and a comment saying why the base interface stays minimal. -
just build,just test,just lintgreen; the JSON-boundary differential still reports 98/98 identical; every touched lexicon passesnpm run build -w @intentius/chant-lexicon-<name>.
Activity
lex00 commentedon Jul 26, 2026
Still valid, but the code moved
#1050 (Phase 2) split the encoder into
packages/core/src/discovery/entity-wire-codec.tsso the sandboxed child's bundle would not drag indiscover()→typescript.entity-wire.tsnow has zeropropsreferences; every cast this issue describes lives in the codec.Updated locations (11
as unknown ascasts in that file, 5 of them props/attributes):The argument for fixing it is now slightly stronger than when filed: this file is the encoder for two sandbox boundaries (resource entities and, by pattern, components), so a resource kind carrying its payload under a differently-named field is silently dropped from the wire rather than caught by the compiler.
Priority unchanged — this is type hygiene, not a live defect, and it sits behind #1020 and #1044 on leverage.
lex00 commentedon Jul 27, 2026
DECISION: option 2 —
ResourceDeclarablesub-interfaceDeclarablestays minimal and honest. Outputs and parameters genuinely have no payload, and widening the base interface with optionalprops?: unknownwould lie about them while still giving no real type safety — it removes the casts without removing the guesswork.Shape:
Every ad-hoc
"props" in entitycheck becomes one guard, and the 5as unknown ascasts inentity-wire-codec.ts(lines ~259, 283–287) go away.Why this one and not the cheaper options
The codec is now the encoder for a process boundary, not just a serializer helper. It decides what data crosses into and back out of the sandboxed child (#1045, #1051). A resource kind whose payload lives under a differently-named field is silently dropped from the wire rather than caught by the compiler, and the 98-entry differential only catches that if some corpus entry happens to exercise that shape.
Centralizing the casts (option 3) fixes the repetition but leaves that failure mode intact. Widening
Declarable(option 1) leaves it intact too, and additionally makes the interface wrong for the kinds that have no props.Scope and sequencing
This touches 10 of the 11 lexicon serializers, so it is the widest blast radius of the three. Do it as a mechanical, single-purpose PR — no behaviour change, no opportunistic cleanups riding along.
Sequence it after #1064 and #1067 land. Both are in flight and #1067 already touches
packages/core/src/lexicon.ts; a wide serializer refactor landing underneath them would create conflicts for no benefit.Acceptance
as unknown asforprops/attributesanywhere inentity-wire-codec.ts.ResourceDeclarable/isResourceDeclarable, not structuralinchecks.propsstill type-checks and still round-trips.npm run build -w @intentius/chant-lexicon-<name>.[-]design(core): Declarable doesn't describe props/attributes, so every consumer casts[/-][+]refactor(core): ResourceDeclarable sub-interface for props/attributes — DECIDED: option 2[/+]refactor(core): ResourceDeclarable sub-interface + guard for props/at…
lex00 commentedon Jul 27, 2026
Shipped in PR #1092 — option 2 as decided: ResourceDeclarable + isResourceDeclarable guard, entity-wire-codec's five casts replaced, 10 serializers (plus forgejo's dialect.ts) routed through the guard. All differentials 98/98 identical, all lexicon builds green. The helm/github duck-typed pockets behind narrower guards are documented in the PR as out of scope.
chore: sync package-lock workspace versions with the 0.20.0 release (#…