Skip to main content

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"]