-
Notifications
You must be signed in to change notification settings - Fork 12.7k
/
Copy pathtypes.ts
1253 lines (1108 loc) · 44.1 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/// <reference path="core.ts"/>
/// <reference path="scanner.ts"/>
module ts {
export interface TextRange {
pos: number;
end: number;
}
// token > SyntaxKind.Identifer => token is a keyword
export enum SyntaxKind {
Unknown,
EndOfFileToken,
SingleLineCommentTrivia,
MultiLineCommentTrivia,
NewLineTrivia,
WhitespaceTrivia,
// Literals
NumericLiteral,
StringLiteral,
RegularExpressionLiteral,
// Punctuation
OpenBraceToken,
CloseBraceToken,
OpenParenToken,
CloseParenToken,
OpenBracketToken,
CloseBracketToken,
DotToken,
DotDotDotToken,
SemicolonToken,
CommaToken,
LessThanToken,
GreaterThanToken,
LessThanEqualsToken,
GreaterThanEqualsToken,
EqualsEqualsToken,
ExclamationEqualsToken,
EqualsEqualsEqualsToken,
ExclamationEqualsEqualsToken,
EqualsGreaterThanToken,
PlusToken,
MinusToken,
AsteriskToken,
SlashToken,
PercentToken,
PlusPlusToken,
MinusMinusToken,
LessThanLessThanToken,
GreaterThanGreaterThanToken,
GreaterThanGreaterThanGreaterThanToken,
AmpersandToken,
BarToken,
CaretToken,
ExclamationToken,
TildeToken,
AmpersandAmpersandToken,
BarBarToken,
QuestionToken,
ColonToken,
// Assignments
EqualsToken,
PlusEqualsToken,
MinusEqualsToken,
AsteriskEqualsToken,
SlashEqualsToken,
PercentEqualsToken,
LessThanLessThanEqualsToken,
GreaterThanGreaterThanEqualsToken,
GreaterThanGreaterThanGreaterThanEqualsToken,
AmpersandEqualsToken,
BarEqualsToken,
CaretEqualsToken,
// Identifiers
Identifier,
// Reserved words
BreakKeyword,
CaseKeyword,
CatchKeyword,
ClassKeyword,
ConstKeyword,
ContinueKeyword,
DebuggerKeyword,
DefaultKeyword,
DeleteKeyword,
DoKeyword,
ElseKeyword,
EnumKeyword,
ExportKeyword,
ExtendsKeyword,
FalseKeyword,
FinallyKeyword,
ForKeyword,
FunctionKeyword,
IfKeyword,
ImportKeyword,
InKeyword,
InstanceOfKeyword,
NewKeyword,
NullKeyword,
ReturnKeyword,
SuperKeyword,
SwitchKeyword,
ThisKeyword,
ThrowKeyword,
TrueKeyword,
TryKeyword,
TypeOfKeyword,
VarKeyword,
VoidKeyword,
WhileKeyword,
WithKeyword,
// Strict mode reserved words
ImplementsKeyword,
InterfaceKeyword,
LetKeyword,
PackageKeyword,
PrivateKeyword,
ProtectedKeyword,
PublicKeyword,
StaticKeyword,
YieldKeyword,
// TypeScript keywords
AnyKeyword,
BooleanKeyword,
ConstructorKeyword,
DeclareKeyword,
GetKeyword,
ModuleKeyword,
RequireKeyword,
NumberKeyword,
SetKeyword,
StringKeyword,
// Parse tree nodes
Missing,
// Names
QualifiedName,
// Signature elements
TypeParameter,
Parameter,
// TypeMember
Property,
Method,
Constructor,
GetAccessor,
SetAccessor,
CallSignature,
ConstructSignature,
IndexSignature,
// Type
TypeReference,
TypeQuery,
TypeLiteral,
ArrayType,
TupleType,
// Expression
ArrayLiteral,
ObjectLiteral,
PropertyAssignment,
PropertyAccess,
IndexedAccess,
CallExpression,
NewExpression,
TypeAssertion,
ParenExpression,
FunctionExpression,
ArrowFunction,
PrefixOperator,
PostfixOperator,
BinaryExpression,
ConditionalExpression,
OmittedExpression,
// Element
Block,
VariableStatement,
EmptyStatement,
ExpressionStatement,
IfStatement,
DoStatement,
WhileStatement,
ForStatement,
ForInStatement,
ContinueStatement,
BreakStatement,
ReturnStatement,
WithStatement,
SwitchStatement,
CaseClause,
DefaultClause,
LabeledStatement,
ThrowStatement,
TryStatement,
TryBlock,
CatchBlock,
FinallyBlock,
DebuggerStatement,
VariableDeclaration,
FunctionDeclaration,
FunctionBlock,
ClassDeclaration,
InterfaceDeclaration,
EnumDeclaration,
ModuleDeclaration,
ModuleBlock,
ImportDeclaration,
ExportAssignment,
// Enum
EnumMember,
// Top-level nodes
SourceFile,
Program,
// Synthesized list
SyntaxList,
// Enum value count
Count,
// Markers
FirstAssignment = EqualsToken,
LastAssignment = CaretEqualsToken,
FirstReservedWord = BreakKeyword,
LastReservedWord = WithKeyword,
FirstKeyword = BreakKeyword,
LastKeyword = StringKeyword,
FirstFutureReservedWord = ImplementsKeyword,
LastFutureReservedWord = YieldKeyword,
FirstTypeNode = TypeReference,
LastTypeNode = TupleType,
FirstPunctuation = OpenBraceToken,
LastPunctuation = CaretEqualsToken,
FirstToken = EndOfFileToken,
LastToken = StringKeyword,
FirstTriviaToken = SingleLineCommentTrivia,
LastTriviaToken = WhitespaceTrivia
}
export enum NodeFlags {
Export = 0x00000001, // Declarations
Ambient = 0x00000002, // Declarations
QuestionMark = 0x00000004, // Parameter/Property/Method
Rest = 0x00000008, // Parameter
Public = 0x00000010, // Property/Method
Private = 0x00000020, // Property/Method
Protected = 0x00000040, // Property/Method
Static = 0x00000080, // Property/Method
MultiLine = 0x00000100, // Multi-line array or object literal
Synthetic = 0x00000200, // Synthetic node (for full fidelity)
DeclarationFile = 0x00000400, // Node is a .d.ts file
Modifier = Export | Ambient | Public | Private | Protected | Static,
AccessibilityModifier = Public | Private | Protected
}
export interface Node extends TextRange {
kind: SyntaxKind;
flags: NodeFlags;
id?: number; // Unique id (used to look up NodeLinks)
parent?: Node; // Parent node (initialized by binding)
symbol?: Symbol; // Symbol declared by node (initialized by binding)
locals?: SymbolTable; // Locals associated with node (initialized by binding)
nextContainer?: Node; // Next container in declaration order (initialized by binding)
localSymbol?: Symbol; // Local symbol declared by node (initialized by binding only for exported nodes)
}
export interface NodeArray<T> extends Array<T>, TextRange {
hasTrailingComma?: boolean;
}
export interface Identifier extends Node {
text: string; // Text of identifier (with escapes converted to characters)
}
export interface QualifiedName extends Node {
// Must have same layout as PropertyAccess
left: EntityName;
right: Identifier;
}
export interface EntityName extends Node {
// Identifier, QualifiedName, or Missing
}
export interface ParsedSignature {
typeParameters?: NodeArray<TypeParameterDeclaration>;
parameters: NodeArray<ParameterDeclaration>;
type?: TypeNode;
}
export interface Declaration extends Node {
name?: Identifier;
}
export interface TypeParameterDeclaration extends Declaration {
constraint?: TypeNode;
}
export interface SignatureDeclaration extends Declaration, ParsedSignature { }
export interface VariableDeclaration extends Declaration {
type?: TypeNode;
initializer?: Expression;
}
export interface PropertyDeclaration extends VariableDeclaration { }
export interface ParameterDeclaration extends VariableDeclaration { }
export interface FunctionDeclaration extends Declaration, ParsedSignature {
body?: Node; // Block or Expression
}
export interface MethodDeclaration extends FunctionDeclaration { }
export interface ConstructorDeclaration extends FunctionDeclaration { }
export interface AccessorDeclaration extends FunctionDeclaration { }
export interface TypeNode extends Node { }
export interface TypeReferenceNode extends TypeNode {
typeName: EntityName;
typeArguments?: NodeArray<TypeNode>;
}
export interface TypeQueryNode extends TypeNode {
exprName: EntityName;
}
export interface TypeLiteralNode extends TypeNode {
members: NodeArray<Node>;
}
export interface ArrayTypeNode extends TypeNode {
elementType: TypeNode;
}
export interface TupleTypeNode extends TypeNode {
elementTypes: NodeArray<TypeNode>;
}
export interface StringLiteralTypeNode extends TypeNode {
text: string;
}
export interface Expression extends Node {
contextualType?: Type; // Used to temporarily assign a contextual type during overload resolution
}
export interface UnaryExpression extends Expression {
operator: SyntaxKind;
operand: Expression;
}
export interface BinaryExpression extends Expression {
left: Expression;
operator: SyntaxKind;
right: Expression;
}
export interface ConditionalExpression extends Expression {
condition: Expression;
whenTrue: Expression;
whenFalse: Expression;
}
export interface FunctionExpression extends Expression, FunctionDeclaration {
body: Node; // Required, whereas the member inherited from FunctionDeclaration is optional
}
// The text property of a LiteralExpression stores the interpreted value of the literal in text form. For a StringLiteral
// this means quotes have been removed and escapes have been converted to actual characters. For a NumericLiteral, the
// stored value is the toString() representation of the number. For example 1, 1.00, and 1e0 are all stored as just "1".
export interface LiteralExpression extends Expression {
text: string;
}
export interface ParenExpression extends Expression {
expression: Expression;
}
export interface ArrayLiteral extends Expression {
elements: NodeArray<Expression>;
}
export interface ObjectLiteral extends Expression {
properties: NodeArray<Node>;
}
export interface PropertyAccess extends Expression {
left: Expression;
right: Identifier;
}
export interface IndexedAccess extends Expression {
object: Expression;
index: Expression;
}
export interface CallExpression extends Expression {
func: Expression;
typeArguments?: NodeArray<TypeNode>;
arguments: NodeArray<Expression>;
}
export interface NewExpression extends CallExpression { }
export interface TypeAssertion extends Expression {
type: TypeNode;
operand: Expression;
}
export interface Statement extends Node { }
export interface Block extends Statement {
statements: NodeArray<Statement>;
}
export interface VariableStatement extends Statement {
declarations: NodeArray<VariableDeclaration>;
}
export interface ExpressionStatement extends Statement {
expression: Expression;
}
export interface IfStatement extends Statement {
expression: Expression;
thenStatement: Statement;
elseStatement?: Statement;
}
export interface IterationStatement extends Statement {
statement: Statement;
}
export interface DoStatement extends IterationStatement {
expression: Expression;
}
export interface WhileStatement extends IterationStatement {
expression: Expression;
}
export interface ForStatement extends IterationStatement {
declarations?: NodeArray<VariableDeclaration>;
initializer?: Expression;
condition?: Expression;
iterator?: Expression;
}
export interface ForInStatement extends IterationStatement {
declaration?: VariableDeclaration;
variable?: Expression;
expression: Expression;
}
export interface BreakOrContinueStatement extends Statement {
label?: Identifier;
}
export interface ReturnStatement extends Statement {
expression?: Expression;
}
export interface WithStatement extends Statement {
expression: Expression;
statement: Statement;
}
export interface SwitchStatement extends Statement {
expression: Expression;
clauses: NodeArray<CaseOrDefaultClause>;
}
export interface CaseOrDefaultClause extends Node {
expression?: Expression;
statements: NodeArray<Statement>;
}
export interface LabeledStatement extends Statement {
label: Identifier;
statement: Statement;
}
export interface ThrowStatement extends Statement {
expression: Expression;
}
export interface TryStatement extends Statement {
tryBlock: Block;
catchBlock?: CatchBlock;
finallyBlock?: Block;
}
export interface CatchBlock extends Block {
variable: Identifier;
}
export interface ClassDeclaration extends Declaration {
typeParameters?: NodeArray<TypeParameterDeclaration>;
baseType?: TypeReferenceNode;
implementedTypes?: NodeArray<TypeReferenceNode>;
members: NodeArray<Node>;
}
export interface InterfaceDeclaration extends Declaration {
typeParameters?: NodeArray<TypeParameterDeclaration>;
baseTypes?: NodeArray<TypeReferenceNode>;
members: NodeArray<Node>;
}
export interface EnumMember extends Declaration {
initializer?: Expression;
}
export interface EnumDeclaration extends Declaration {
members: NodeArray<EnumMember>;
}
export interface ModuleDeclaration extends Declaration {
body: Node; // Block or ModuleDeclaration
}
export interface ImportDeclaration extends Declaration {
entityName?: EntityName;
externalModuleName?: LiteralExpression;
}
export interface ExportAssignment extends Statement {
exportName: Identifier;
}
export interface FileReference extends TextRange {
filename: string;
}
export interface CommentRange extends TextRange {
hasTrailingNewLine?: boolean;
}
export interface SourceFile extends Block {
filename: string;
text: string;
getLineAndCharacterFromPosition(position: number): { line: number; character: number };
getPositionFromLineAndCharacter(line: number, character: number): number;
amdDependencies: string[];
referencedFiles: FileReference[];
syntacticErrors: Diagnostic[];
semanticErrors: Diagnostic[];
hasNoDefaultLib: boolean;
externalModuleIndicator: Node; // The first node that causes this file to be an external module
nodeCount: number;
identifierCount: number;
symbolCount: number;
isOpen: boolean;
version: string;
languageVersion: ScriptTarget;
identifiers: Map<string>;
}
export interface Program {
getSourceFile(filename: string): SourceFile;
getSourceFiles(): SourceFile[];
getCompilerOptions(): CompilerOptions;
getCompilerHost(): CompilerHost;
getDiagnostics(sourceFile?: SourceFile): Diagnostic[];
getGlobalDiagnostics(): Diagnostic[];
getTypeChecker(fullTypeCheckMode: boolean): TypeChecker;
getCommonSourceDirectory(): string;
}
export interface SourceMapSpan {
/** Line number in the js file*/
emittedLine: number;
/** Column number in the js file */
emittedColumn: number;
/** Line number in the ts file */
sourceLine: number;
/** Column number in the ts file */
sourceColumn: number;
/** Optional name (index into names array) associated with this span */
nameIndex?: number;
/** ts file (index into sources array) associated with this span*/
sourceIndex: number;
}
export interface SourceMapData {
/** Where the sourcemap file is written */
sourceMapFilePath: string;
/** source map URL written in the js file */
jsSourceMappingURL: string;
/** Source map's file field - js file name*/
sourceMapFile: string;
/** Source map's sourceRoot field - location where the sources will be present if not "" */
sourceMapSourceRoot: string;
/** Source map's sources field - list of sources that can be indexed in this source map*/
sourceMapSources: string[];
/** input source file (which one can use on program to get the file)
this is one to one mapping with the sourceMapSources list*/
inputSourceFileNames: string[];
/** Source map's names field - list of names that can be indexed in this source map*/
sourceMapNames?: string[];
/** Source map's mapping field - encoded source map spans*/
sourceMapMappings: string;
/** Raw source map spans that were encoded into the sourceMapMappings*/
sourceMapDecodedMappings: SourceMapSpan[];
}
// Return code used by getEmitOutput function to indicate status of the function
export enum EmitReturnStatus {
Succeeded = 0, // All outputs generated as requested (.js, .map, .d.ts), no errors reported
AllOutputGenerationSkipped = 1, // No .js generated because of syntax errors, nothing generated
JSGeneratedWithSemanticErrors = 2, // .js and .map generated with semantic errors
DeclarationGenerationSkipped = 3, // .d.ts generation skipped because of semantic errors or declaration emitter specific errors; Output .js with semantic errors
EmitErrorsEncountered = 4, // Emitter errors occurred during emitting process
CompilerOptionsErrors = 5, // Errors occurred in parsing compiler options, nothing generated
}
export interface EmitResult {
emitResultStatus: EmitReturnStatus;
errors: Diagnostic[];
sourceMaps: SourceMapData[]; // Array of sourceMapData if compiler emitted sourcemaps
}
export interface TypeChecker {
getProgram(): Program;
getDiagnostics(sourceFile?: SourceFile): Diagnostic[];
getGlobalDiagnostics(): Diagnostic[];
getNodeCount(): number;
getIdentifierCount(): number;
getSymbolCount(): number;
getTypeCount(): number;
checkProgram(): void;
emitFiles(targetSourceFile?: SourceFile): EmitResult;
getParentOfSymbol(symbol: Symbol): Symbol;
getTypeOfSymbol(symbol: Symbol): Type;
getPropertiesOfType(type: Type): Symbol[];
getPropertyOfType(type: Type, propetyName: string): Symbol;
getSignaturesOfType(type: Type, kind: SignatureKind): Signature[];
getIndexTypeOfType(type: Type, kind: IndexKind): Type;
getReturnTypeOfSignature(signature: Signature): Type;
getSymbolsInScope(location: Node, meaning: SymbolFlags): Symbol[];
getSymbolInfo(node: Node): Symbol;
getTypeOfNode(node: Node): Type;
getApparentType(type: Type): ApparentType;
typeToString(type: Type, enclosingDeclaration?: Node, flags?: TypeFormatFlags): string;
symbolToString(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags): string;
typeToDisplayParts(type: Type, enclosingDeclaration?: Node, flags?: TypeFormatFlags): SymbolDisplayPart[];
symbolToDisplayParts(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags): SymbolDisplayPart[];
getFullyQualifiedName(symbol: Symbol): string;
getAugmentedPropertiesOfApparentType(type: Type): Symbol[];
getRootSymbol(symbol: Symbol): Symbol;
getContextualType(node: Node): Type;
getResolvedSignature(node: CallExpression, candidatesOutArray?: Signature[]): Signature;
// Returns the constant value of this enum member, or 'undefined' if the enum member has a
// computed value.
getEnumMemberValue(node: EnumMember): number;
}
export interface TextWriter {
write(s: string): void;
trackSymbol(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags): void;
writeLine(): void;
increaseIndent(): void;
decreaseIndent(): void;
getText(): string;
}
export enum TypeFormatFlags {
None = 0x00000000,
WriteArrayAsGenericType = 0x00000001, // Write Array<T> instead T[]
UseTypeOfFunction = 0x00000002, // Write typeof instead of function type literal
NoTruncation = 0x00000004, // Don't truncate typeToString result
}
export enum SymbolAccessibility {
Accessible,
NotAccessible,
CannotBeNamed
}
export interface SymbolAccessiblityResult {
accessibility: SymbolAccessibility;
errorSymbolName?: string // Optional symbol name that results in error
errorModuleName?: string // If the symbol is not visible from module, module's name
aliasesToMakeVisible?: ImportDeclaration[]; // aliases that need to have this symbol visible
}
export interface EmitResolver {
getProgram(): Program;
getLocalNameOfContainer(container: Declaration): string;
getExpressionNamePrefix(node: Identifier): string;
getExportAssignmentName(node: SourceFile): string;
isReferencedImportDeclaration(node: ImportDeclaration): boolean;
isTopLevelValueImportedViaEntityName(node: ImportDeclaration): boolean;
getNodeCheckFlags(node: Node): NodeCheckFlags;
getEnumMemberValue(node: EnumMember): number;
hasSemanticErrors(): boolean;
isDeclarationVisible(node: Declaration): boolean;
isImplementationOfOverload(node: FunctionDeclaration): boolean;
isPrivatePropertyAccess(node: PropertyAccess): boolean;
isStaticPropertyAccess(node: PropertyAccess): boolean;
writeTypeAtLocation(location: Node, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: TextWriter): void;
writeReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: TextWriter): void;
isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult;
isImportDeclarationEntityNameReferenceDeclarationVisibile(entityName: EntityName): SymbolAccessiblityResult;
// Returns the constant value this property access resolves to, or 'undefined' if it does
// resolve to a constant.
getConstantValue(node: PropertyAccess): number;
}
export enum SymbolFlags {
Variable = 0x00000001, // Variable or parameter
Property = 0x00000002, // Property or enum member
EnumMember = 0x00000004, // Enum member
Function = 0x00000008, // Function
Class = 0x00000010, // Class
Interface = 0x00000020, // Interface
Enum = 0x00000040, // Enum
ValueModule = 0x00000080, // Instantiated module
NamespaceModule = 0x00000100, // Uninstantiated module
TypeLiteral = 0x00000200, // Type Literal
ObjectLiteral = 0x00000400, // Object Literal
Method = 0x00000800, // Method
Constructor = 0x00001000, // Constructor
GetAccessor = 0x00002000, // Get accessor
SetAccessor = 0x00004000, // Set accessor
CallSignature = 0x00008000, // Call signature
ConstructSignature = 0x00010000, // Construct signature
IndexSignature = 0x00020000, // Index signature
TypeParameter = 0x00040000, // Type parameter
// Export markers (see comment in declareModuleMember in binder)
ExportValue = 0x00080000, // Exported value marker
ExportType = 0x00100000, // Exported type marker
ExportNamespace = 0x00200000, // Exported namespace marker
Import = 0x00400000, // Import
Instantiated = 0x00800000, // Instantiated symbol
Merged = 0x01000000, // Merged symbol (created during program binding)
Transient = 0x02000000, // Transient symbol (created during type check)
Prototype = 0x04000000, // Symbol for the prototype property (without source code representation)
Value = Variable | Property | EnumMember | Function | Class | Enum | ValueModule | Method | GetAccessor | SetAccessor,
Type = Class | Interface | Enum | TypeLiteral | ObjectLiteral | TypeParameter,
Namespace = ValueModule | NamespaceModule,
Module = ValueModule | NamespaceModule,
Accessor = GetAccessor | SetAccessor,
Signature = CallSignature | ConstructSignature | IndexSignature,
ParameterExcludes = Value,
VariableExcludes = Value & ~Variable,
PropertyExcludes = Value,
EnumMemberExcludes = Value,
FunctionExcludes = Value & ~(Function | ValueModule),
ClassExcludes = (Value | Type) & ~ValueModule,
InterfaceExcludes = Type & ~Interface,
EnumExcludes = (Value | Type) & ~(Enum | ValueModule),
ValueModuleExcludes = Value & ~(Function | Class | Enum | ValueModule),
NamespaceModuleExcludes = 0,
MethodExcludes = Value & ~Method,
GetAccessorExcludes = Value & ~SetAccessor,
SetAccessorExcludes = Value & ~GetAccessor,
TypeParameterExcludes = Type & ~TypeParameter,
// Imports collide with all other imports with the same name.
ImportExcludes = Import,
ModuleMember = Variable | Function | Class | Interface | Enum | Module | Import,
ExportHasLocal = Function | Class | Enum | ValueModule,
HasLocals = Function | Module | Method | Constructor | Accessor | Signature,
HasExports = Class | Enum | Module,
HasMembers = Class | Interface | TypeLiteral | ObjectLiteral,
IsContainer = HasLocals | HasExports | HasMembers,
PropertyOrAccessor = Property | Accessor,
Export = ExportNamespace | ExportType | ExportValue,
}
export interface Symbol {
flags: SymbolFlags; // Symbol flags
name: string; // Name of symbol
id?: number; // Unique id (used to look up SymbolLinks)
mergeId?: number; // Merge id (used to look up merged symbol)
declarations?: Declaration[]; // Declarations associated with this symbol
parent?: Symbol; // Parent symbol
members?: SymbolTable; // Class, interface or literal instance members
exports?: SymbolTable; // Module exports
exportSymbol?: Symbol; // Exported symbol associated with this symbol
valueDeclaration?: Declaration // First value declaration of the symbol
}
export interface SymbolLinks {
target?: Symbol; // Resolved (non-alias) target of an alias
type?: Type; // Type of value symbol
declaredType?: Type; // Type of class, interface, enum, or type parameter
mapper?: TypeMapper; // Type mapper for instantiation alias
referenced?: boolean; // True if alias symbol has been referenced as a value
exportAssignSymbol?: Symbol; // Symbol exported from external module
}
export interface TransientSymbol extends Symbol, SymbolLinks { }
export interface SymbolTable {
[index: string]: Symbol;
}
export enum NodeCheckFlags {
TypeChecked = 0x00000001, // Node has been type checked
LexicalThis = 0x00000002, // Lexical 'this' reference
CaptureThis = 0x00000004, // Lexical 'this' used in body
EmitExtends = 0x00000008, // Emit __extends
SuperInstance = 0x00000010, // Instance 'super' reference
SuperStatic = 0x00000020, // Static 'super' reference
ContextChecked = 0x00000040, // Contextual types have been assigned
// Values for enum members have been computed, and any errors have been reported for them.
EnumValuesComputed = 0x00000080,
}
export interface NodeLinks {
resolvedType?: Type; // Cached type of type node
resolvedSignature?: Signature; // Cached signature of signature node or call expression
resolvedSymbol?: Symbol; // Cached name resolution result
flags?: NodeCheckFlags; // Set of flags specific to Node
enumMemberValue?: number; // Constant value of enum member
isIllegalTypeReferenceInConstraint?: boolean; // Is type reference in constraint refers to the type parameter from the same list
isVisible?: boolean; // Is this node visible
localModuleName?: string; // Local name for module instance
}
export enum TypeFlags {
Any = 0x00000001,
String = 0x00000002,
Number = 0x00000004,
Boolean = 0x00000008,
Void = 0x00000010,
Undefined = 0x00000020,
Null = 0x00000040,
Enum = 0x00000080, // Enum type
StringLiteral = 0x00000100, // String literal type
TypeParameter = 0x00000200, // Type parameter
Class = 0x00000400, // Class
Interface = 0x00000800, // Interface
Reference = 0x00001000, // Generic type reference
Tuple = 0x00002000, // Tuple
Anonymous = 0x00004000, // Anonymous
FromSignature = 0x00008000, // Created for signature assignment check
Intrinsic = Any | String | Number | Boolean | Void | Undefined | Null,
StringLike = String | StringLiteral,
NumberLike = Number | Enum,
ObjectType = Class | Interface | Reference | Tuple | Anonymous
}
// Properties common to all types
export interface Type {
flags: TypeFlags; // Flags
id: number; // Unique ID
symbol?: Symbol; // Symbol associated with type (if any)
}
// Intrinsic types (TypeFlags.Intrinsic)
export interface IntrinsicType extends Type {
intrinsicName: string; // Name of intrinsic type
}
// String literal types (TypeFlags.StringLiteral)
export interface StringLiteralType extends Type {
text: string; // Text of string literal
}
// Object types (TypeFlags.ObjectType)
export interface ObjectType extends Type { }
export interface ApparentType extends Type {
// This property is not used. It is just to make the type system think ApparentType
// is a strict subtype of Type.
_apparentTypeBrand: any;
}
// Class and interface types (TypeFlags.Class and TypeFlags.Interface)
export interface InterfaceType extends ObjectType {
typeParameters: TypeParameter[]; // Type parameters (undefined if non-generic)
baseTypes: ObjectType[]; // Base types
declaredProperties: Symbol[]; // Declared members
declaredCallSignatures: Signature[]; // Declared call signatures
declaredConstructSignatures: Signature[]; // Declared construct signatures
declaredStringIndexType: Type; // Declared string index type
declaredNumberIndexType: Type; // Declared numeric index type
}
// Type references (TypeFlags.Reference)
export interface TypeReference extends ObjectType {
target: GenericType; // Type reference target
typeArguments: Type[]; // Type reference type arguments
}
// Generic class and interface types
export interface GenericType extends InterfaceType, TypeReference {
instantiations: Map<TypeReference>; // Generic instantiation cache
openReferenceTargets: GenericType[]; // Open type reference targets
openReferenceChecks: Map<boolean>; // Open type reference check cache
}
export interface TupleType extends ObjectType {
elementTypes: Type[]; // Element types
baseArrayType: TypeReference; // Array<T> where T is best common type of element types
}
// Resolved object type
export interface ResolvedObjectType extends ObjectType {
members: SymbolTable; // Properties by name
properties: Symbol[]; // Properties
callSignatures: Signature[]; // Call signatures of type
constructSignatures: Signature[]; // Construct signatures of type
stringIndexType: Type; // String index type
numberIndexType: Type; // Numeric index type
}
// Type parameters (TypeFlags.TypeParameter)
export interface TypeParameter extends Type {
constraint: Type; // Constraint
target?: TypeParameter; // Instantiation target
mapper?: TypeMapper; // Instantiation mapper
}
export enum SignatureKind {
Call,
Construct,
}
export interface Signature {
declaration: SignatureDeclaration; // Originating declaration
typeParameters: TypeParameter[]; // Type parameters (undefined if non-generic)
parameters: Symbol[]; // Parameters
resolvedReturnType: Type; // Resolved return type
minArgumentCount: number; // Number of non-optional parameters
hasRestParameter: boolean; // True if last parameter is rest parameter
hasStringLiterals: boolean; // True if specialized
target?: Signature; // Instantiation target
mapper?: TypeMapper; // Instantiation mapper
erasedSignatureCache?: Signature; // Erased version of signature (deferred)
isolatedSignatureType?: ObjectType; // A manufactured type that just contains the signature for purposes of signature comparison
}
export enum IndexKind {
String,
Number,
}
export interface TypeMapper {
(t: Type): Type;
}
export interface InferenceContext {
typeParameters: TypeParameter[];
inferences: Type[][];
inferredTypes: Type[];
}
export interface DiagnosticMessage {
key: string;
category: DiagnosticCategory;
code: number;
}
// A linked list of formatted diagnostic messages to be used as part of a multiline message.
// It is built from the bottom up, leaving the head to be the "main" diagnostic.
// While it seems that DiagnosticMessageChain is structurally similar to DiagnosticMessage,
// the difference is that messages are all preformatted in DMC.
export interface DiagnosticMessageChain {
messageText: string;
category: DiagnosticCategory;
code: number;
next?: DiagnosticMessageChain;
}
export interface Diagnostic {
file: SourceFile;
start: number;
length: number;
messageText: string;
category: DiagnosticCategory;
code: number;
}
export enum DiagnosticCategory {
Warning,
Error,
Message,
}
export interface CompilerOptions {
charset?: string;
codepage?: number;
declaration?: boolean;