Size / Priority
- Size: Trivial (~10 sites)
- Category: C.3 Type-Safety.
- Risk: low.
Affected files
src/crdt/*Codec.ts — CRDT codec functions.
src/crdt/DistributedData.ts — decodeCrdt returns Crdt<any>.
Background
CRDTs are generic: GCounter, GSet<T>, LWWRegister<T>, etc. The framework's codec functions sometimes use any for the value type:
// src/crdt/DistributedData.ts:49
export function decodeCrdt(json: CrdtJson): Crdt<any> {
// ...
}
any defeats the type system: callers can do anything with the result without type errors.
The audit suggests Crdt<unknown> — at least the compiler forces a narrowing before use.
Target
Replace any with unknown (or specific generic bounds where possible):
// Before:
export function decodeCrdt(json: CrdtJson): Crdt<any> { ... }
// After:
export function decodeCrdt(json: CrdtJson): Crdt<unknown> { ... }
// Callers:
const crdt = decodeCrdt(json);
// crdt.value has type unknown; user must narrow before using.
Similar replacements in other CRDT codecs.
Integration / risk
- Caller-side changes: callers that did
crdt.value.foo directly now need narrowing.
- Internal-only
any cases: some internal interfaces may still need any for variance reasons; document each.
Test plan
- Regression — CRDT tests pass.
- Compile-time: callers that didn't narrow now error.
- Per-narrow fix: each erroring caller adds a type-guard.
Acceptance criteria
Size / Priority
Affected files
src/crdt/*Codec.ts— CRDT codec functions.src/crdt/DistributedData.ts—decodeCrdtreturnsCrdt<any>.Background
CRDTs are generic:
GCounter,GSet<T>,LWWRegister<T>, etc. The framework's codec functions sometimes useanyfor the value type:anydefeats the type system: callers can do anything with the result without type errors.The audit suggests
Crdt<unknown>— at least the compiler forces a narrowing before use.Target
Replace
anywithunknown(or specific generic bounds where possible):Similar replacements in other CRDT codecs.
Integration / risk
crdt.value.foodirectly now need narrowing.anycases: some internal interfaces may still needanyfor variance reasons; document each.Test plan
Acceptance criteria
anyreplaced withunknownin CRDT codecs.