-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
is_not_function.ts
75 lines (72 loc) · 2.13 KB
/
is_not_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
63
64
65
66
67
68
69
70
71
72
73
74
75
import type { $SelectInvert } from '../type_plus/branch/$select_invert.js'
/**
* Is `T` not a `Function`.
*
* ```ts
* type R = IsNotFunction<Function> // false
* type R = IsNotFunction<() => void> // false
* type R = IsNotFunction<(() => void) | { a: 1 }> // false
*
* type R = IsNotFunction<{ a: 1 }> // true
* type R = IsNotFunction<never> // true
* ```
*/
/**
* 🎭 *predicate*
*
* Validate if `T` is not `Function` nor function signature.
*
* @example
* ```ts
* type R = IsNotFunction<Function> // false
* type R = IsNotFunction<() => void> // false
*
* type R = IsNotFunction<never> // true
* type R = IsNotFunction<unknown> // true
* type R = IsNotFunction<number> // true
*
* type R = IsNotFunction<Function | number> // boolean
* type R = IsNotFunction<(() => string) | number> // boolean
* ```
*
* 🔢 *customize*
*
* Filter to ensure `T` is not `Function` nor function signature, otherwise returns `never`.
*
* @example
* ```ts
* type R = IsNotFunction<Function, { selection: 'filter' }> // never
* type R = IsNotFunction<() => void, { selection: 'filter' }> // never
*
* type R = IsNotFunction<never, { selection: 'filter' }> // never
* type R = IsNotFunction<unknown, { selection: 'filter' }> // unknown
* type R = IsNotFunction<Function | number, { selection: 'filter' }> // number
*
* type R = IsNotFunction<(() => string) | number, { selection: 'filter' }> // number
* ```
*
* 🔢 *customize*:
*
* Disable distribution of union types.
*
* ```ts
* type R = IsNotFunction<Function | 1> // boolean
* type R = IsNotFunction<Function | 1, { distributive: false }> // false
* ```
*
* 🔢 *customize*
*
* Use unique branch identifiers to allow precise processing of the result.
*
* @example
* ```ts
* type R = IsNotFunction<Function, $SelectionBranch> // $Then
* type R = IsNotFunction<string, $SelectionBranch> // $Else
* ```
*/
export type IsNotFunction<T, $O extends IsNotFunction.$Options = {}> = $SelectInvert<T, Function, $O>
export namespace IsNotFunction {
export type $Options = $SelectInvert.$Options
export type $Default = $SelectInvert.$Default
export type $Branch = $SelectInvert.$Branch
}