apps-script-utils 2.1.1 Help

nonConsistent2DArray

function nonConsistent2DArray<T>(arr: T | Array<Array<unknown>>): arr is T;

nonConsistent2DArray(value) is the same test as !isConsistent2DArray(value), written so that a guard clause reads forwards — see Validation conventions.

Like non2DArray, it is best used for its boolean answer: after the check TypeScript does not hand back a usable matrix type. requireConsistent2DArray is what validates and returns the matrix.

It reports true for two different situations: a matrix whose rows differ in length, and a value that is not a matrix at all. They are indistinguishable from the result alone, so use non2DArray when the difference matters.

Parameters

Parameter

Type

Description

arr

T \| Array<Array<unknown>>

The value to check.

Returns

boolean — true if the value is not a non-empty array of arrays of equal length; otherwise false.

In TypeScript the guard narrows arr to T inside the branch.

Examples

Both failing cases

nonConsistent2DArray([[1, 2], [3]]); // => true — ragged nonConsistent2DArray([1, 2]); // => true — not 2D nonConsistent2DArray([ [1, 2], [3, 4] ]); // => false

Telling the two apart

/** * Tells the two failure cases apart: not a matrix at all, versus a matrix * whose rows differ in length. */ export function describeShape(rows: unknown): string { if (non2DArray(rows)) { return "not a matrix"; } if (nonConsistent2DArray(rows)) { return "a matrix, but the rows differ in length"; } return "ready for setValues"; }
function describeShape(rows) { if (non2DArray(rows)) { return "not a matrix"; } if (nonConsistent2DArray(rows)) { return "a matrix, but the rows differ in length"; } return "ready for setValues"; }

See also

Source

src/lang/array/nonConsistent2DArray.ts

23 September 2026

This documentation was generated with AI (Claude) from the library's source code.