tsentials/array

Enforce non-empty array invariants with TypeScript types and utilities.

49|Updated May 12, 2026
One-click install
npx skills add https://github.com/senrecep/tsentials --skill tsentials-array
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: tsentials/array
Source: https://github.com/senrecep/tsentials/tree/main/.well-known/agent-skills/tsentials-array
Command: npx skills add https://github.com/senrecep/tsentials --skill tsentials-array

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

It solves the problem of unsafe array access by providing a type-safe way to represent arrays that are guaranteed to contain at least one element.

Core Features & Use Cases

  • NonEmptyArray<T> type: Represents Array<T> with the invariant that index 0 exists, eliminating undefined checks for operations like head and last.
  • Runtime narrowing and conversions: Use asNonEmptyArray to convert a plain array into a safe Option-like outcome, and isNonEmpty as a type guard.
  • Invariant-preserving operations: Use utilities such as reverse that preserve the non-empty guarantee, while transform/utility functions like filter intentionally return arrays that may become empty.
  • Use cases: Validating user input lists, processing pipelines that require at least one item, and building deterministic business rules where empty collections are invalid states.

Quick Start

Use the NonEmptyArray helpers to enforce that your function inputs must contain at least one element, and convert from a possibly-empty array with asNonEmptyArray when needed.

Frequently Asked Questions about tsentials/array

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I guarantee a TypeScript array is non-empty at runtime?

To guarantee a TypeScript array is non-empty, use a type guard like isNonEmpty to narrow the type or asNonEmptyArray to convert it into a safe Option-like outcome for deterministic access.

What's the best way to safely get the first or last element of an array in TypeScript?

The best way to safely get the first or last element is by using a NonEmptyArray type, which enforces that index 0 exists and eliminates the need for undefined checks on head and last operations.

How do I validate user input lists that require at least one item in TypeScript?

To validate user input lists requiring at least one item, apply runtime narrowing with isNonEmpty to ensure the collection is valid before processing it through deterministic business rules.

Does filtering a NonEmptyArray preserve the non-empty type invariant in TypeScript?

Filtering a NonEmptyArray does not preserve the non-empty invariant, as the resulting array may become empty; however, operations like reverse intentionally maintain the non-empty guarantee.

Why do I still get undefined errors when accessing array elements with TypeScript?

Undefined errors occur because standard TypeScript arrays allow empty states; using a NonEmptyArray representation enforces the invariant that index 0 exists, eliminating these unsafe access errors.

Can I use non-empty array helpers for processing pipelines that require at least one item?

Yes, you can use non-empty array helpers for processing pipelines by applying asNonEmptyArray to convert plain arrays, ensuring every downstream operation safely handles collections requiring at least one item.