UNPKG

561 BTypeScriptView Raw
1import type {IsEqual} from './is-equal';
2
3/**
4Returns a boolean for whether the given array includes the given item.
5
6This can be useful if another type wants to make a decision based on whether the array includes that item.
7
8@example
9```
10import type {Includes} from 'type-fest';
11
12type hasRed<array extends any[]> = Includes<array, 'red'>;
13```
14
15@category Array
16*/
17export type Includes<Value extends readonly any[], Item> =
18 Value extends readonly [Value[0], ...infer rest]
19 ? IsEqual<Value[0], Item> extends true
20 ? true
21 : Includes<rest, Item>
22 : false;