-
Notifications
You must be signed in to change notification settings - Fork 1
/
TypeRepresentation.ts
69 lines (62 loc) · 1.95 KB
/
TypeRepresentation.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
export type TypeRep = NumberRep | BooleanRep | BigIntRep | StringRep | SymbolRep | NullRep | UndefinedRep
| VoidRep | AnyRep | UnknownRep | NeverRep | NonPrimitiveRep | UnionRep | IntersectionRep | ObjectRep;
export enum TypeKind { //@TODO: Categorize Better & Provide more information through representation.
Any,
Number,
Boolean,
String,
Symbol,
BigInt,
Null,
Undefined,
NonPrimitive,
Unknown,
Never,
Void,
Enum, //@TODO
This,
Object, //@TODO
Function, //@TODO
Array,
Tuple,
Union,
Intersection,
TemplateLiteral, //@TODO
Class, //@TODO
}
interface TypeRepresentation<K extends TypeKind> {
kind: K;
}
export interface NumberRep extends TypeRepresentation<TypeKind.Number> {
literal: number;
}
export interface BooleanRep extends TypeRepresentation<TypeKind.Boolean> {
literal: boolean;
}
export interface BigIntRep extends TypeRepresentation<TypeKind.BigInt> {
literal: bigint;
}
export interface StringRep extends TypeRepresentation<TypeKind.String> {
literal: string;
}
export type SymbolRep = TypeRepresentation<TypeKind.Symbol>;
export type NullRep = TypeRepresentation<TypeKind.Null>;
export type UndefinedRep = TypeRepresentation<TypeKind.Undefined>;
export type VoidRep = TypeRepresentation<TypeKind.Void>;
export type AnyRep = TypeRepresentation<TypeKind.Any>;
export type UnknownRep = TypeRepresentation<TypeKind.Unknown>;
export type NeverRep = TypeRepresentation<TypeKind.Never>;
export type NonPrimitiveRep = TypeRepresentation<TypeKind.NonPrimitive>;
export interface ObjectRep extends TypeRepresentation<TypeKind.Object> {
properties: [string, TypeRep][];
}
export interface UnionRep extends TypeRepresentation<TypeKind.Union> {
parts: TypeRep[];
}
export interface IntersectionRep extends TypeRepresentation<TypeKind.Intersection> {
parts: TypeRep[];
}
export interface FunctionRep extends TypeRepresentation<TypeKind.Function> { //@TODO Support Type Parameter
parameters: TypeRep[];
returnType: TypeRep;
}