Skip to content

nonEmptyArray

Matcher for a non-empty array.

Matchers are applied through assertObjectMatches, where they narrow the corresponding property type.

Type information that already exists in the calling scope is incorporated.

import { assertObjectMatches, nonEmptyArray } from "@kensio/smartass";
const value: unknown = {
tags: ["typescript", "testing"],
};
assertObjectMatches(value, {
tags: nonEmptyArray(),
});
// value is now narrowed to an object with a non-empty tags array
// {
// tags: [unknown, ...unknown[]];
// }

Source file: src/assert/array-not-empty/array-not-empty.match.ts