Aller au contenu principal

Arrayable<T>

Arrayable<T> = T | T[]

Represents a value that can be either a single item or an array of items.


Type Parameters

T: T

The base type.


Since

2.0.0


Example

function processItems(items: `Arrayable<string>`): string[] {
return Array.isArray(items) ? items : [items];
}

processItems("single"); // Returns ["single"]
processItems(["a", "b"]); // Returns ["a", "b"]