Array is heterogeneous¶
arrayIsHeterogeneous is a built‑in scan rule that detects arrays whose elements have mixed structural types.
It compares the structural type of the first element against each subsequent element. When a mismatch is found, the rule emits a warn‑level array.is.heterogeneous scan event containing the observed types. If the value is not an array, or all elements share the same structural type, no events are emitted.
Signature¶
export const arrayIsHeterogeneous: ScanRule (raw: unknown, path: FieldPath) => JaneEvent[]
Events¶
| Event code | Description |
|---|---|
array.is.heterogeneous |
Array contains elements with differing types. |
Design rationale¶
- Detects inconsistent structural types within arrays.
- Uses
detectStructuralTypeto ensure consistent type classification across all elements. - Emits a warning when the first element’s type differs from any subsequent element.
- Helps surface malformed or inconsistent list shapes early in the pipeline.
- Provides type metadata (
{ firstType, mixedType }) for policy and analysis. - Performs no mutation or restructuring of the input.
Invoke¶
arrayIsHeterogeneous runs automatically whenever the scan stage is enabled.
Activation methods:
- Enable scan explicitly:
jane.value(input).scan(). - Use a mode that enables scan:
strict()enables scan by default.moderate()andlax()do not enable scan unless.scan()is called.- Enable scan with policy:
jane.value(input).withPolicy({ mode: 'strict' }).
If scan is not enabled or the structural type is not an array, arrayIsHeterogeneous does not run and no heterogeneity detection occurs.
Examples¶
Heterogeneous array detected¶
const result = arrayIsHeterogeneous([1, "a"], "$");
// → [ JaneEvent{ kind: "warn", code: "array.is.heterogeneous", ... } ]
Homogeneous array¶
const result = arrayIsHeterogeneous([1, 2, 3], "$");
// → []
Non‑array value¶
const result = arrayIsHeterogeneous("not an array", "$");
// → []