Files
openclaw/packages/normalization-core/src/expect.ts
Peter Steinberger e686693732 feat(tooling): adopt noUncheckedIndexedAccess via a strict-ratchet lane (phase 1) (#104577)
* feat(tooling): add noUncheckedIndexedAccess strict-ratchet lane

* fix(packages): make indexed access explicit across ratchet packages

Burns down all 65 noUncheckedIndexedAccess errors in the seven ratchet
packages with behavior-identical restructuring (iteration, charAt/slice,
regex-group guards, validated hextet tuple). net-policy invariant
violations now throw instead of failing open. Adds
@openclaw/normalization-core/expect (expectDefined/first/last) with
subpath export and tests. memory-host-sdk fixes kept but the package
stays out of the lane: it re-exports core src/** so the flag would apply
transitively to all of core.

* fix(lint): keep .oxlintrc.json strict-JSON parseable for extension lint wrappers
2026-07-11 10:26:12 -07:00

18 lines
637 B
TypeScript

/** Returns the value or throws with the named context; use for genuine invariants only. */
export function expectDefined<T>(value: T | null | undefined, context: string): T {
if (value === null || value === undefined) {
throw new Error("expected " + context + " to be defined");
}
return value;
}
/** First element with honest optionality; callers own the absent case. */
export function first<T>(values: readonly T[]): T | undefined {
return values.at(0);
}
/** Last element with honest optionality; callers own the absent case. */
export function last<T>(values: readonly T[]): T | undefined {
return values.at(-1);
}