-
-
Notifications
You must be signed in to change notification settings - Fork 679
Expand file tree
/
Copy pathincludes.d.ts
More file actions
24 lines (18 loc) · 578 Bytes
/
includes.d.ts
File metadata and controls
24 lines (18 loc) · 578 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import type {IsEqual} from './is-equal.d.ts';
/**
Returns a boolean for whether the given array includes the given item.
This can be useful if another type wants to make a decision based on whether the array includes that item.
@example
```
import type {Includes} from 'type-fest';
type hasRed<array extends any[]> = Includes<array, 'red'>;
```
@category Array
*/
export type Includes<Value extends readonly any[], Item> =
Value extends readonly [Value[0], ...infer rest]
? IsEqual<Value[0], Item> extends true
? true
: Includes<rest, Item>
: false;
export {};