No undefined items¶
noUndefinedItems validates that an array does not contain any undefined items, including sparse array holes.
It performs a strict structural array check and rejects any non‑array value. If the value is an array and contains either an explicit undefined element or a hole (an index not present in the array), the rule emits a single validation event. Otherwise, it produces no validation output.
Signature¶
Through the API:
.noUndefinedItems();
And internally:
export const noUndefinedItems: ValidationRule
(value: unknown, path: FieldPath) => Promise<ReadonlyArray<JaneEvent>>
Events¶
| Event code | Description |
|---|---|
array.not.array |
Value is not structurally an array. |
array.has.undefined-items |
Array contains undefined values or sparse array holes. |
Design rationale¶
- Enforces strict, predictable validation that disallows both explicit undefined values and sparse array holes.
- Rejects non‑array values with a structural‑type diagnostic.
- Uses explicit index checks (
iinvalue) to detect holes, ensuring contributors cannot accidentally pass sparse arrays. - Emits exactly one event per failure for clarity and composability.
- Never coerces, normalizes, or transforms — validation is explicit and opt‑in.
- Async‑compatible and returns a readonly array of
JaneEventobjects.
Invoke¶
noUndefinedItems runs only when explicitly included in a boundary or pipeline. It does not run automatically.
The rule activates when:
- The value is any JavaScript value.
- If the value is not an array, emits
array.not.array. - Emits
array.has.undefined-itemsif the value is an array and contains: - An explicit
undefinedvalue - A sparse array hole
(!(i in value)) - Otherwise, returns an empty result set.
Examples¶
Valid — no undefined values or holes¶
await noUndefinedItems([1, 2, 3], "$");
// → []
Invalid — explicit undefined¶
await noUndefinedItems([1, undefined, 3], "$");
// → [
// JaneEvent{
// kind: "error",
// code: "array.has.undefined-items",
// path: "$",
// ...
// }
// ]
Invalid — sparse array hole¶
const arr = [];
arr[2] = "x"; // hole at index 0 and 1
await noUndefinedItems(arr, "$");
// → [
// JaneEvent{
// kind: "error",
// code: "array.has.undefined-items",
// path: "$",
// ...
// }
// ]