UNPKG

9 kBPlain TextView Raw
1/**
2 * `ModuleDeclarations` contains the different kinds of declarations
3 * exported by a module (for example, a package, a module (file) or a namespace).
4 */
5export interface ModuleDeclarations {
6 readonly variables: VariableDeclaration[];
7 readonly functions: FunctionDeclaration[];
8 readonly classes: ClassDeclaration[];
9 readonly interfaces: InterfaceDeclaration[];
10 readonly enums: EnumDeclaration[];
11 readonly typeAliases: TypeAliasDeclaration[];
12 readonly namespaces: NamespaceDeclaration[];
13}
14
15/**
16 * `VariableDeclaration` represents a variable declaration
17 * (for example, `const myVar = ...`).
18 */
19export interface VariableDeclaration extends Declaration {
20 readonly kind: DeclarationKinds.VariableDeclaration;
21
22 /** Either `var`, `let`, or `const` */
23 readonly variableKind: string;
24
25 /** Variable type (for example, `string`) */
26 readonly type: string;
27}
28
29/**
30 * `FunctionDeclaration` represents a normal function declaration
31 * (for example, `function myFunc() {...}`)
32 * or a named function expression
33 * (for example, `const myFunc = () => {...}` or
34 * `const myFunc = function() {...}`).
35 */
36export interface FunctionDeclaration extends Declaration {
37 readonly kind: DeclarationKinds.FunctionDeclaration;
38
39 /** Function type (for example, `() => string`) */
40 readonly type: string;
41}
42
43/**
44 * `ClassDeclaration` represents a class declaration
45 * (for example, `class MyClass {...}`).
46 */
47export interface ClassDeclaration extends Declaration {
48 readonly kind: DeclarationKinds.ClassDeclaration;
49
50 /** If `true`, the class is abstract */
51 readonly isAbstract: boolean;
52
53 /** Class constructors */
54 readonly constructors: ClassConstructorDeclaration[];
55
56 /** Class members */
57 readonly members: ClassMemberDeclarations;
58}
59
60/**
61 * `ClassConstructorDeclaration` represents a constructor declaration
62 * belonging to a class (for example, `constructor() {...}`).
63 */
64export interface ClassConstructorDeclaration extends Declaration {
65 readonly kind: DeclarationKinds.ClassConstructorDeclaration;
66}
67
68/**
69 * `ClassMemberDeclarations` contains the members of a class.
70 */
71export interface ClassMemberDeclarations {
72 readonly properties: ClassPropertyDeclaration[];
73 readonly methods: ClassMethodDeclaration[];
74}
75
76/**
77 * `ClassPropertyDeclaration` represents a property defined in a class
78 * either directly (for example, `foo: string`)
79 * or through an accessor (for example, `get foo(): string {...}`).
80 */
81export interface ClassPropertyDeclaration extends Declaration {
82 readonly kind: DeclarationKinds.ClassPropertyDeclaration;
83
84 /** If `true`, the property is static */
85 readonly isStatic: boolean;
86
87 /** Property type (for example, `string`) */
88 readonly type: string;
89}
90
91/**
92 * `ClassMethodDeclaration` represents a method defined in a class
93 * (for example, `foo(): string {...}`).
94 */
95export interface ClassMethodDeclaration extends Declaration {
96 readonly kind: DeclarationKinds.ClassMethodDeclaration;
97
98 /** If `true`, the method is static */
99 readonly isStatic: boolean;
100
101 /** Method type (for example, `() => string`) */
102 readonly type: string;
103}
104
105/**
106 * `InterfaceDeclaration` represents an interface declaration
107 * (for example, `interface MyInterface {...}`).
108 */
109export interface InterfaceDeclaration extends Declaration {
110 readonly kind: DeclarationKinds.InterfaceDeclaration;
111
112 /** Interface members */
113 readonly members: InterfaceMemberDeclarations;
114}
115
116/**
117 * `InterfaceMemberDeclarations` contains the members of an interface.
118 */
119export interface InterfaceMemberDeclarations {
120 readonly properties: InterfacePropertyDeclaration[];
121 readonly methods: InterfaceMethodDeclaration[];
122 readonly constructSignatures: InterfaceConstructSignatureDeclaration[];
123 readonly callSignatures: InterfaceCallSignatureDeclaration[];
124 readonly indexSignatures: InterfaceIndexSignatureDeclaration[];
125}
126
127/**
128 * `InterfacePropertyDeclaration` represents a property defined in an interface
129 * (for example, `foo: string` in `interface MyInterface { foo: string }`).
130 */
131export interface InterfacePropertyDeclaration extends Declaration {
132 readonly kind: DeclarationKinds.InterfacePropertyDeclaration;
133
134 /** If `true`, the property is `readonly` */
135 readonly isReadonly: boolean;
136
137 /** If `true`, the property is optional */
138 readonly isOptional: boolean;
139
140 /** Property type (for example, `string`) */
141 readonly type: string;
142}
143
144/**
145 * `InterfaceMethodDeclaration` represents a method defined in an interface
146 * (for example, `foo(): string` in `interface MyInterface { foo(): string }`).
147 */
148export interface InterfaceMethodDeclaration extends Declaration {
149 readonly kind: DeclarationKinds.InterfaceMethodDeclaration;
150
151 /** Method signature type (for example, `() => string`) */
152 readonly type: string;
153}
154
155/**
156 * `InterfaceConstructSignatureDeclaration` represents a construct signature
157 * defined in an interface (for example, `new (foo: string)`).
158 */
159export interface InterfaceConstructSignatureDeclaration extends Declaration {
160 readonly kind: DeclarationKinds.InterfaceConstructSignatureDeclaration;
161}
162
163/**
164 * `InterfaceCallSignatureDeclaration` represents a call signature
165 * defined in an interface (for example, `(foo: string): boolean`).
166 */
167export interface InterfaceCallSignatureDeclaration extends Declaration {
168 readonly kind: DeclarationKinds.InterfaceCallSignatureDeclaration;
169}
170
171/**
172 * `InterfaceIndexSignatureDeclaration` represents an index signature
173 * defined in an interface (for example, `[index: number]: string`).
174 */
175export interface InterfaceIndexSignatureDeclaration extends Declaration {
176 readonly kind: DeclarationKinds.InterfaceIndexSignatureDeclaration;
177}
178
179/**
180 * `EnumDeclaration` represents an enum declaration
181 * (for example, `enum MyEnum {...}`).
182 */
183export interface EnumDeclaration extends Declaration {
184 readonly kind: DeclarationKinds.EnumDeclaration;
185
186 /** If `true`, the enum is a constant enum. */
187 readonly isConst: boolean;
188
189 /** Enum members */
190 readonly members: EnumMemberDeclaration[];
191}
192
193/**
194 * `EnumMemberDeclaration` represents a member defined in an enum
195 * (for example, `UP` in `enum MyEnum { UP, DOWN }`).
196 */
197export interface EnumMemberDeclaration extends Declaration {
198 readonly kind: DeclarationKinds.EnumMemberDeclaration;
199
200 /** Member's constant value */
201 readonly value?: string | number;
202}
203
204/**
205 * `TypeAliasDeclaration` represents a type alias declaration
206 * (for example, `type myType = ...`).
207 */
208export interface TypeAliasDeclaration extends Declaration {
209 readonly kind: DeclarationKinds.TypeAliasDeclaration;
210}
211
212/**
213 * `NamespaceDeclaration` represents a namespace declaration
214 * (for example, `namespace MyNamespace {...}`).
215 */
216export interface NamespaceDeclaration extends Declaration {
217 readonly kind: DeclarationKinds.NamespaceDeclaration;
218
219 /** Exported namespace declarations */
220 readonly declarations: ModuleDeclarations;
221}
222
223/**
224 * `Declaration` contains the properties common to all declaration kinds.
225 */
226export interface Declaration {
227 /** Declaration kind */
228 readonly kind: DeclarationKinds;
229
230 /** Declaration ID */
231 readonly id: string;
232
233 /** Export name */
234 readonly name: string;
235
236 /** Documentation comments describing the declaration */
237 readonly docs: string[];
238
239 /** Location in the source code */
240 readonly source: DeclarationSource;
241
242 /** Declaration's signature */
243 readonly signature: string;
244}
245
246/**
247 * `DeclarationKinds` lists the possible kinds of declarations
248 */
249export enum DeclarationKinds {
250 VariableDeclaration = 'VariableDeclaration',
251 FunctionDeclaration = 'FunctionDeclaration',
252 ClassDeclaration = 'ClassDeclaration',
253 ClassConstructorDeclaration = 'ClassConstructorDeclaration',
254 ClassPropertyDeclaration = 'ClassPropertyDeclaration',
255 ClassMethodDeclaration = 'ClassMethodDeclaration',
256 InterfaceDeclaration = 'InterfaceDeclaration',
257 InterfacePropertyDeclaration = 'InterfacePropertyDeclaration',
258 InterfaceMethodDeclaration = 'InterfaceMethodDeclaration',
259 InterfaceConstructSignatureDeclaration = 'InterfaceConstructSignatureDeclaration',
260 InterfaceCallSignatureDeclaration = 'InterfaceCallSignatureDeclaration',
261 InterfaceIndexSignatureDeclaration = 'InterfaceIndexSignatureDeclaration',
262 EnumDeclaration = 'EnumDeclaration',
263 EnumMemberDeclaration = 'EnumMemberDeclaration',
264 TypeAliasDeclaration = 'TypeAliasDeclaration',
265 NamespaceDeclaration = 'NamespaceDeclaration',
266}
267
268/**
269 * `DeclarationSource` represents the location of a declaration in a source file.
270 */
271export interface DeclarationSource {
272 /** Filename */
273 readonly filename: string;
274
275 /** Starting line number */
276 readonly line: number;
277
278 /** URL in a remote repository linking to the declaration */
279 readonly url?: string;
280
281 /** URL on unpkg.com linking to the declaration */
282 readonly unpkgURL?: string;
283}