1
+ /**
2
+ * The function interface.
3
+ */
4
+ export type Func < A extends any [ ] = any [ ] , R = any > = ( ...args : A ) => R
5
+
1
6
/**
2
7
* Gets the keys of type `T` matching the `V` values.
3
8
*/
4
- declare type KeysMatching < T , V > = { [ K in keyof T ] -?: T [ K ] extends V ? K : never } [ keyof T ]
9
+ export type KeysMatching < T , V > = { [ K in keyof T ] -?: T [ K ] extends V ? K : never } [ keyof T ]
5
10
6
11
/**
7
12
* A Dictionary type for keeping `TValue` values.
8
13
*/
9
- declare type Dictionary < TValue > = { [ key : string ] : TValue }
14
+ export type Dictionary < TValue > = { [ key : string ] : TValue }
10
15
11
16
/**
12
17
* Maps the given type to its function keys.
13
18
* If the given type is an array, then the function indices will be returned.
14
19
* If the given type is an object, then the function keys will be returned.
15
20
*/
16
- declare type FunctionKeys < T >
21
+ export type FunctionKeys < T >
17
22
= T extends any [ ]
18
23
? Exclude < _FunctionKeys < T > , - 1 >
19
24
: T extends { [ key : string ] : any }
@@ -23,43 +28,43 @@ declare type FunctionKeys<T>
23
28
/**
24
29
* Defines the nullable version of given type.
25
30
*/
26
- declare type Nullable < T > = T | null | undefined
31
+ export type Nullable < T > = T | null | undefined
27
32
28
33
/**
29
34
* Defines the nullable version of given type with `void` type.
30
35
*/
31
- declare type NullableReturn < T > = Nullable < T > | void
36
+ export type NullableReturn < T > = Nullable < T > | void
32
37
33
38
/**
34
39
* Defines a type which can be in a promise or not.
35
40
*/
36
- declare type MaybePromise < T > = Promise < T > | T
41
+ export type MaybePromise < T > = Promise < T > | T
37
42
38
43
/**
39
44
* Gets the keys of an object whose values are objects.
40
45
*
41
46
* This does not include function keys.
42
47
*/
43
- declare type ObjectKeys < T extends object >
48
+ export type ObjectKeys < T extends object >
44
49
= Exclude < KeysMatching < T , object > , FunctionKeys < T > >
45
50
46
51
/**
47
52
* Gets the length of an array.
48
53
*/
49
- declare type Length < T extends any [ ] > = T extends { length : infer L } ? L : never
54
+ export type Length < T extends any [ ] > = T extends { length : infer L } ? L : never
50
55
51
56
/**
52
57
* Builds a tuple with given length.
53
58
*/
54
- declare type BuildTuple < L extends number , T extends any [ ] = [ ] >
59
+ export type BuildTuple < L extends number , T extends any [ ] = [ ] >
55
60
= T extends { length : L } ? T : BuildTuple < L , [ ...T , any ] >
56
61
57
- type _FunctionKeys < TArray extends any [ ] , CurrentIndex = 0 , Index = - 1 >
62
+ type _FunctionKeys < TArray extends any [ ] , CurrentIndex extends number = 0 , Index = - 1 >
58
63
= TArray extends [ infer H , ...infer T ]
59
64
? H extends Func
60
65
? _FunctionKeys < T , Add < CurrentIndex , 1 > , Index | CurrentIndex >
61
66
: _FunctionKeys < T , Add < CurrentIndex , 1 > , Index >
62
67
: Index
63
68
64
69
type Add < A extends number , B extends number > =
65
- Length < [ ...BuildTuple < A > , ...BuildTuple < B > ] >
70
+ Length < [ ...BuildTuple < A > , ...BuildTuple < B > ] > & number
0 commit comments