@@ -67,6 +67,7 @@ module ts {
67
67
var stringType = createIntrinsicType(TypeFlags.String, "string");
68
68
var numberType = createIntrinsicType(TypeFlags.Number, "number");
69
69
var booleanType = createIntrinsicType(TypeFlags.Boolean, "boolean");
70
+ var esSymbolType = createIntrinsicType(TypeFlags.ESSymbol, "symbol");
70
71
var voidType = createIntrinsicType(TypeFlags.Void, "void");
71
72
var undefinedType = createIntrinsicType(TypeFlags.Undefined | TypeFlags.ContainsUndefinedOrNull, "undefined");
72
73
var nullType = createIntrinsicType(TypeFlags.Null | TypeFlags.ContainsUndefinedOrNull, "null");
@@ -123,6 +124,10 @@ module ts {
123
124
"boolean": {
124
125
type: booleanType,
125
126
flags: TypeFlags.Boolean
127
+ },
128
+ "symbol": {
129
+ type: esSymbolType,
130
+ flags: TypeFlags.ESSymbol
126
131
}
127
132
};
128
133
@@ -3191,6 +3196,8 @@ module ts {
3191
3196
return numberType;
3192
3197
case SyntaxKind.BooleanKeyword:
3193
3198
return booleanType;
3199
+ case SyntaxKind.SymbolKeyword:
3200
+ return esSymbolType;
3194
3201
case SyntaxKind.VoidKeyword:
3195
3202
return voidType;
3196
3203
case SyntaxKind.StringLiteral:
@@ -5492,7 +5499,7 @@ module ts {
5492
5499
function isNumericComputedName(name: ComputedPropertyName): boolean {
5493
5500
// It seems odd to consider an expression of type Any to result in a numeric name,
5494
5501
// but this behavior is consistent with checkIndexedAccess
5495
- return isTypeOfKind(checkComputedPropertyName(name), TypeFlags.Any | TypeFlags.NumberLike, /*includeESSymbols*/ false );
5502
+ return isTypeOfKind(checkComputedPropertyName(name), TypeFlags.Any | TypeFlags.NumberLike);
5496
5503
}
5497
5504
5498
5505
function isNumericLiteralName(name: string) {
@@ -5527,7 +5534,7 @@ module ts {
5527
5534
5528
5535
// This will allow types number, string, Symbol or any. It will also allow enums, the unknown
5529
5536
// type, and any union of these types (like string | number).
5530
- if (!isTypeOfKind(links.resolvedType, TypeFlags.Any | TypeFlags.NumberLike | TypeFlags.StringLike, /*includeESSymbols*/ true )) {
5537
+ if (!isTypeOfKind(links.resolvedType, TypeFlags.Any | TypeFlags.NumberLike | TypeFlags.StringLike | TypeFlags.ESSymbol )) {
5531
5538
error(node, Diagnostics.A_computed_property_name_must_be_of_type_string_number_Symbol_or_any);
5532
5539
}
5533
5540
}
@@ -5792,10 +5799,10 @@ module ts {
5792
5799
}
5793
5800
5794
5801
// Check for compatible indexer types.
5795
- if (isTypeOfKind(indexType, TypeFlags.Any | TypeFlags.StringLike | TypeFlags.NumberLike, /*includeESSymbols*/ true )) {
5802
+ if (isTypeOfKind(indexType, TypeFlags.Any | TypeFlags.StringLike | TypeFlags.NumberLike | TypeFlags.ESSymbol )) {
5796
5803
5797
5804
// Try to use a number indexer.
5798
- if (isTypeOfKind(indexType, TypeFlags.Any | TypeFlags.NumberLike, /*includeESSymbols*/ false )) {
5805
+ if (isTypeOfKind(indexType, TypeFlags.Any | TypeFlags.NumberLike)) {
5799
5806
var numberIndexType = getIndexTypeOfType(objectType, IndexKind.Number);
5800
5807
if (numberIndexType) {
5801
5808
return numberIndexType;
@@ -6733,7 +6740,7 @@ module ts {
6733
6740
}
6734
6741
6735
6742
function checkArithmeticOperandType(operand: Node, type: Type, diagnostic: DiagnosticMessage): boolean {
6736
- if (!isTypeOfKind(type, TypeFlags.Any | TypeFlags.NumberLike, /*includeESSymbols*/ false )) {
6743
+ if (!isTypeOfKind(type, TypeFlags.Any | TypeFlags.NumberLike)) {
6737
6744
error(operand, diagnostic);
6738
6745
return false;
6739
6746
}
@@ -6884,29 +6891,20 @@ module ts {
6884
6891
return numberType;
6885
6892
}
6886
6893
6887
- // Return true if type has the given flags, or is a union type composed of types that all have those flags
6888
- // If include includeESSymbols is true, then check if the type (or union constituents) is an ESSymbol
6889
- // if it does not match the kind. This is necessary because ESSymbol has no corresponding flag.
6890
- function isTypeOfKind(type: Type, kind: TypeFlags, includeESSymbols: boolean): boolean {
6894
+ // Return true if type has the given flags, or is a union type composed of types that all have those flags.
6895
+ function isTypeOfKind(type: Type, kind: TypeFlags): boolean {
6891
6896
if (type.flags & kind) {
6892
6897
return true;
6893
6898
}
6894
6899
if (type.flags & TypeFlags.Union) {
6895
6900
var types = (<UnionType>type).types;
6896
6901
for (var i = 0; i < types.length; i++) {
6897
- if (types[i].flags & kind) {
6898
- continue;
6899
- }
6900
- if (includeESSymbols && types[i] === globalESSymbolType) {
6901
- continue;
6902
+ if (!(types[i].flags & kind)) {
6903
+ return false;
6902
6904
}
6903
- return false;
6904
6905
}
6905
6906
return true;
6906
6907
}
6907
- if (includeESSymbols) {
6908
- return type === globalESSymbolType;
6909
- }
6910
6908
return false;
6911
6909
}
6912
6910
@@ -6924,11 +6922,7 @@ module ts {
6924
6922
// and the right operand to be of type Any or a subtype of the 'Function' interface type.
6925
6923
// The result is always of the Boolean primitive type.
6926
6924
// NOTE: do not raise error if leftType is unknown as related error was already reported
6927
- //
6928
- // The reason for globalESSymbolType !== unknownType is that if the type is unknownType, we don't want to error.
6929
- // If the globalESSymbolType is also unknownType, then by including globalESSymbolType, we will error
6930
- // on unknownType, because transitively, type will be the same as globalESSymbolType.
6931
- if (isTypeOfKind(leftType, TypeFlags.Primitive, /*includeESSymbols*/ globalESSymbolType !== unknownType)) {
6925
+ if (isTypeOfKind(leftType, TypeFlags.Primitive)) {
6932
6926
error(node.left, Diagnostics.The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter);
6933
6927
}
6934
6928
// NOTE: do not raise error if right is unknown as related error was already reported
@@ -6943,10 +6937,10 @@ module ts {
6943
6937
// The in operator requires the left operand to be of type Any, the String primitive type, or the Number primitive type,
6944
6938
// and the right operand to be of type Any, an object type, or a type parameter type.
6945
6939
// The result is always of the Boolean primitive type.
6946
- if (!isTypeOfKind(leftType, TypeFlags.Any | TypeFlags.StringLike | TypeFlags.NumberLike, /*includeESSymbols*/ true )) {
6940
+ if (!isTypeOfKind(leftType, TypeFlags.Any | TypeFlags.StringLike | TypeFlags.NumberLike | TypeFlags.ESSymbol )) {
6947
6941
error(node.left, Diagnostics.The_left_hand_side_of_an_in_expression_must_be_of_types_any_string_or_number);
6948
6942
}
6949
- if (!isTypeOfKind(rightType, TypeFlags.Any | TypeFlags.ObjectType | TypeFlags.TypeParameter, /*includeESSymbols*/ false )) {
6943
+ if (!isTypeOfKind(rightType, TypeFlags.Any | TypeFlags.ObjectType | TypeFlags.TypeParameter)) {
6950
6944
error(node.right, Diagnostics.The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter);
6951
6945
}
6952
6946
return booleanType;
@@ -7107,12 +7101,12 @@ module ts {
7107
7101
if (rightType.flags & (TypeFlags.Undefined | TypeFlags.Null)) rightType = leftType;
7108
7102
7109
7103
var resultType: Type;
7110
- if (isTypeOfKind(leftType, TypeFlags.NumberLike, /*includeESSymbols*/ false ) && isTypeOfKind(rightType, TypeFlags.NumberLike, /*includeESSymbols*/ false )) {
7104
+ if (isTypeOfKind(leftType, TypeFlags.NumberLike) && isTypeOfKind(rightType, TypeFlags.NumberLike)) {
7111
7105
// Operands of an enum type are treated as having the primitive type Number.
7112
7106
// If both operands are of the Number primitive type, the result is of the Number primitive type.
7113
7107
resultType = numberType;
7114
7108
}
7115
- else if (isTypeOfKind(leftType, TypeFlags.StringLike, /*includeESSymbols*/ false ) || isTypeOfKind(rightType, TypeFlags.StringLike, /*includeESSymbols*/ false )) {
7109
+ else if (isTypeOfKind(leftType, TypeFlags.StringLike) || isTypeOfKind(rightType, TypeFlags.StringLike)) {
7116
7110
// If one or both operands are of the String primitive type, the result is of the String primitive type.
7117
7111
resultType = stringType;
7118
7112
}
@@ -8478,7 +8472,7 @@ module ts {
8478
8472
// and Expr must be an expression of type Any, an object type, or a type parameter type.
8479
8473
var varExpr = <Expression>node.initializer;
8480
8474
var exprType = checkExpression(varExpr);
8481
- if (!isTypeOfKind(exprType, TypeFlags.Any | TypeFlags.StringLike, /*includeESSymbols*/ true )) {
8475
+ if (!isTypeOfKind(exprType, TypeFlags.Any | TypeFlags.StringLike)) {
8482
8476
error(varExpr, Diagnostics.The_left_hand_side_of_a_for_in_statement_must_be_of_type_string_or_any);
8483
8477
}
8484
8478
else {
@@ -8490,7 +8484,7 @@ module ts {
8490
8484
var exprType = checkExpression(node.expression);
8491
8485
// unknownType is returned i.e. if node.expression is identifier whose name cannot be resolved
8492
8486
// in this case error about missing name is already reported - do not report extra one
8493
- if (!isTypeOfKind(exprType, TypeFlags.Any | TypeFlags.ObjectType | TypeFlags.TypeParameter, /*includeESSymbols*/ false )) {
8487
+ if (!isTypeOfKind(exprType, TypeFlags.Any | TypeFlags.ObjectType | TypeFlags.TypeParameter)) {
8494
8488
error(node.expression, Diagnostics.The_right_hand_side_of_a_for_in_statement_must_be_of_type_any_an_object_type_or_a_type_parameter);
8495
8489
}
8496
8490
0 commit comments