-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
is_function.ts
62 lines (60 loc) · 1.75 KB
/
is_function.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import type { $Select } from '../type_plus/branch/$select.js'
/**
* 🎭 *predicate*
*
* Validate if `T` is `Function` or function signature.
*
* @example
* ```ts
* type R = IsFunction<Function> // true
* type R = IsFunction<() => void> // true
*
* type R = IsFunction<never> // false
* type R = IsFunction<unknown> // false
* type R = IsFunction<number> // false
*
* type R = IsFunction<Function | number> // boolean
* type R = IsFunction<(() => string) | number> // boolean
* ```
*
* 🔢 *customize*
*
* Filter to ensure `T` is `Function` or function signature, otherwise returns `never`.
*
* @example
* ```ts
* type R = IsFunction<Function, { selection: 'filter' }> // Function
* type R = IsFunction<() => void, { selection: 'filter' }> // () => void
*
* type R = IsFunction<never, { selection: 'filter' }> // never
* type R = IsFunction<unknown, { selection: 'filter' }> // never
* type R = IsFunction<Function | number, { selection: 'filter' }> // Function
*
* type R = IsFunction<(() => string) | number, { selection: 'filter' }> // () => string
* ```
*
* 🔢 *customize*:
*
* Disable distribution of union types.
*
* ```ts
* type R = IsFunction<Function | 1> // boolean
* type R = IsFunction<Function | 1, { distributive: false }> // false
* ```
*
* 🔢 *customize*
*
* Use unique branch identifiers to allow precise processing of the result.
*
* @example
* ```ts
* type R = IsFunction<Function, $SelectionBranch> // $Then
* type R = IsFunction<string, $SelectionBranch> // $Else
* ```
*/
export type IsFunction<T, $O extends IsFunction.$Options = {}> = $Select<T, Function, $O>
export namespace IsFunction {
export type $Options = $Select.$Options
export type $Default = $Select.$Default
export type $Branch = $Select.$Branch
}