type NonEmptyArray = [T, ...T[]]; // Example Usage: function processItems(items: NonEmptyArray) { // We are guaranteed that items has at least one element. console.log('First item:', items[0]); return items.length; } const validItems: NonEmptyArray = ['apple', 'banana']; console.log(processItems(validItems)); // Output: First item: apple, 2 // const emptyItems: NonEmptyArray = []; // Type error: Source has 0 elements, but target requires 1. const singleItem: NonEmptyArray = [100]; console.log(processItems(singleItem)); // Output: First item: 100, 1 // Using with type guards: function checkIfNonEmpty(arr: T[]): arr is NonEmptyArray { return arr.length > 0; } const potentialItems: string[] = []; if (checkIfNonEmpty(potentialItems)) { // Inside this block, potentialItems is of type NonEmptyArray console.log(potentialItems[0]); // Safe access } const emptyArray: string[] = []; // processItems(emptyArray); // Type error: Argument of type 'string[]' is not assignable to parameter of type 'NonEmptyArray'.