UNPKG

537 BTypeScriptView Raw
1/**
2Create a type that represents either the value or an array of the value.
3
4@see Promisable
5
6@example
7```
8import type {Arrayable} from 'type-fest';
9
10function bundle(input: string, output: Arrayable<string>) {
11 const outputList = Array.isArray(output) ? output : [output];
12
13 // …
14
15 for (const output of outputList) {
16 console.log(`write to: ${output}`);
17 }
18}
19
20bundle('src/index.js', 'dist/index.js');
21bundle('src/index.js', ['dist/index.cjs', 'dist/index.mjs']);
22```
23
24@category Array
25*/
26export type Arrayable<T> = T | readonly T[];