Sometimes a function should accept either a single item or an array of items. Use Array.isArray to decide which one you have and normalize to one consistent shape.
function ensureArray(s: string | string[]) {
return Array.isArray(s) ? s : [s];
}Return a new array every time so callers can safely reuse the result.
Normalize input into an array of strings.
asList(v: string | string[]): string[].v is a string, return [v].v is an array, return a new array with the same elements (do not return the input reference).