This repository has been archived by the owner on May 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtypes.ts
87 lines (76 loc) · 3.54 KB
/
types.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
76
77
78
79
80
81
82
83
84
85
86
87
/*******************************************************************************
* Fn Type
*
* Represents a function with arbitrary arity of arguments
******************************************************************************/
export type Fn<AS extends unknown[], B> = (...as: AS) => B;
/*******************************************************************************
* UnknownFn Type
*
* Represents a function with unknown unputs and output
******************************************************************************/
export type UnknownFn = Fn<unknown[], unknown>;
/*******************************************************************************
* Nil Type
*
* An alias for undefined | null
******************************************************************************/
export type Nil = undefined | null;
/*******************************************************************************
* Lazy<A> Type
*
* An alias type that turns `A` into `() => A` (aka Const)
******************************************************************************/
export type Lazy<A> = () => A;
/*******************************************************************************
* Predicate<A>
*
* An alias for a function that takes type A and returns a boolean
******************************************************************************/
export type Predicate<A> = Fn<[A], boolean>;
/*******************************************************************************
* Guard<A>
*
* An alias for the TypeScript type guard function
******************************************************************************/
export type Guard<A> = (a: unknown) => a is A;
/*******************************************************************************
* Refinement<A, B extends A>
*
* An alias for a function that takes an A type and refines it to a B type
******************************************************************************/
export type Refinement<A, B extends A> = (a: A) => a is B;
/*******************************************************************************
* Ordering Type
*
* Ordering is a type alias for -1 | 0 | 1 consts
******************************************************************************/
export type Ordering = -1 | 0 | 1;
/*******************************************************************************
* NonEmptyRecord<R>
*
* NonEmptyRecord<R> returns R only if it has properties, otherwise it
* coerces to never. When used in the argument position this forces a generic
* to have keys.
******************************************************************************/
export type NonEmptyRecord<R> = keyof R extends never ? never : R;
/*******************************************************************************
* Return
*
* Extracts the return type of a function type
******************************************************************************/
// deno-lint-ignore no-explicit-any
export type Return<T> = T extends (...as: any[]) => infer R ? R : never;
/*******************************************************************************
* Args
*
* Extracts the argument types of a function type
******************************************************************************/
// deno-lint-ignore no-explicit-any
export type Args<T> = T extends (...as: infer AS) => any ? AS : never;
/*******************************************************************************
* Or
*
* Replaces a type A with B if B doesn't extend never;
******************************************************************************/
export type Or<A, B> = B extends never ? A : B;