-
-
Notifications
You must be signed in to change notification settings - Fork 549
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
Create a type that represents either the value or array of the value. | ||
@see Promisable | ||
@example | ||
``` | ||
import type {Arrayable} from 'type-fest'; | ||
function bundle(input: string, output: Arrayable<string>) { | ||
const outputList = Array.isArray(output) ? output : [output]; | ||
// ... | ||
for (const output of outputList) { | ||
console.log(`write to: ${output}`); | ||
} | ||
} | ||
bundle('src/index.js', 'dist/index.js'); | ||
bundle('src/index.js', ['dist/index.cjs', 'dist/index.mjs']); | ||
``` | ||
@category Array | ||
*/ | ||
export type Arrayable<T> = T | T[]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import {expectType} from 'tsd'; | ||
import type {Arrayable} from '../index'; | ||
|
||
declare const unknown: unknown; | ||
|
||
expectType<Arrayable<string>>(unknown as string | string[]); | ||
expectType<Arrayable<string | {foo: number}>>(unknown as (string | {foo: number}) | Array<string | {foo: number}>); | ||
expectType<Arrayable<never>>(unknown as /* never | */ never[]); | ||
expectType<Arrayable<string[]>>(unknown as string[] | string[][]); |