assertMatrix

Asserts that a value is a matrix, narrowing its type, and throws if it is not.

import { Matrix } from "@teakit/matrix";

const input: unknown = { "2024": [1, 2] };

Matrix.assertMatrix(input);
// input is now typed as Matrix<unknown>; no clone is made.
Matrix.sum(input); // 3

Matrix.assertMatrix([1, 2]); // throws MatrixError "MATRIX_INVALID_MATRIX"

API Reference

Signature

Matrix.assertMatrix(value: unknown): asserts value is Matrix<unknown>;

Parameters

ParameterTypeRequiredNotes
valueunknownYesValue to assert.

Returns

void. Narrows value to Matrix<unknown> on success. Does not clone.

Throws

  • MATRIX_INVALID_MATRIX — value is not a valid matrix structure (same rule as from).

Agent Contract

FieldValue
Kindstatic assertion
Canonical nameassertMatrix
AliasesNone
Mutates inputsNo
Returnsasserts value is Matrix<unknown>

Agent Notes

  • Use assertMatrix when an invalid value should be an error; use isMatrix when you want a boolean branch.
  • It validates only; to also get a key-ascending clone, use from.