Skip to content

Commit a298835

Browse files
committed
Addressing CR feedback
1 parent d6eb486 commit a298835

2 files changed

Lines changed: 30 additions & 27 deletions

File tree

src/compiler/checker.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ module ts {
6666
var numberType = createIntrinsicType(TypeFlags.Number, "number");
6767
var booleanType = createIntrinsicType(TypeFlags.Boolean, "boolean");
6868
var voidType = createIntrinsicType(TypeFlags.Void, "void");
69-
var undefinedType = createIntrinsicType(TypeFlags.Undefined | TypeFlags.ContainsUndefined, "undefined");
70-
var nullType = createIntrinsicType(TypeFlags.Null | TypeFlags.ContainsUndefined, "null");
69+
var undefinedType = createIntrinsicType(TypeFlags.Undefined | TypeFlags.ContainsUndefinedOrNull, "undefined");
70+
var nullType = createIntrinsicType(TypeFlags.Null | TypeFlags.ContainsUndefinedOrNull, "null");
7171
var unknownType = createIntrinsicType(TypeFlags.Any, "unknown");
7272
var resolvingType = createIntrinsicType(TypeFlags.Any, "__resolving__");
7373

@@ -2807,6 +2807,9 @@ module ts {
28072807
}
28082808
}
28092809

2810+
// This function is used to propagate widening flags when creating new object types references and union types.
2811+
// It is only necessary to do so if a constituent type might be the undefined type, the null type, or the type
2812+
// of an object literal (since those types have widening related information we need to track).
28102813
function getWideningFlagsOfTypes(types: Type[]): TypeFlags {
28112814
var result: TypeFlags = 0;
28122815
for (var i = 0; i < types.length; i++) {
@@ -4111,7 +4114,7 @@ module ts {
41114114
var symbol = <TransientSymbol>createSymbol(p.flags | SymbolFlags.Transient, p.name);
41124115
symbol.declarations = p.declarations;
41134116
symbol.parent = p.parent;
4114-
symbol.type = getWidenedType(getTypeOfSymbol(p));
4117+
symbol.type = widenedType;
41154118
symbol.target = p;
41164119
if (p.valueDeclaration) symbol.valueDeclaration = p.valueDeclaration;
41174120
p = symbol;
@@ -4160,7 +4163,7 @@ module ts {
41604163
var errorReported = false;
41614164
forEach(getPropertiesOfObjectType(type), p => {
41624165
var t = getTypeOfSymbol(p);
4163-
if (t.flags & TypeFlags.ContainsUndefined) {
4166+
if (t.flags & TypeFlags.ContainsUndefinedOrNull) {
41644167
if (!reportWideningErrorsInType(t)) {
41654168
error(p.valueDeclaration, Diagnostics.Object_literal_s_property_0_implicitly_has_an_1_type, p.name, typeToString(getWidenedType(t)));
41664169
}
@@ -4204,7 +4207,7 @@ module ts {
42044207
}
42054208

42064209
function reportErrorsFromWidening(declaration: Declaration, type: Type) {
4207-
if (produceDiagnostics && compilerOptions.noImplicitAny && type.flags & TypeFlags.ContainsUndefined) {
4210+
if (produceDiagnostics && compilerOptions.noImplicitAny && type.flags & TypeFlags.ContainsUndefinedOrNull) {
42084211
// Report implicit any error within type if possible, otherwise report error on declaration
42094212
if (!reportWideningErrorsInType(type)) {
42104213
reportImplicitAnyError(declaration, type);
@@ -5464,7 +5467,7 @@ module ts {
54645467
var stringIndexType = getIndexType(IndexKind.String);
54655468
var numberIndexType = getIndexType(IndexKind.Number);
54665469
var result = createAnonymousType(node.symbol, properties, emptyArray, emptyArray, stringIndexType, numberIndexType);
5467-
result.flags |= TypeFlags.ObjectLiteral | TypeFlags.ContainsLiteral | (typeFlags & TypeFlags.ContainsUndefined);
5470+
result.flags |= TypeFlags.ObjectLiteral | TypeFlags.ContainsObjectLiteral | (typeFlags & TypeFlags.ContainsUndefinedOrNull);
54685471
return result;
54695472

54705473
function getIndexType(kind: IndexKind) {

src/compiler/types.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,32 +1266,32 @@ module ts {
12661266
}
12671267

12681268
export const enum TypeFlags {
1269-
Any = 0x00000001,
1270-
String = 0x00000002,
1271-
Number = 0x00000004,
1272-
Boolean = 0x00000008,
1273-
Void = 0x00000010,
1274-
Undefined = 0x00000020,
1275-
Null = 0x00000040,
1276-
Enum = 0x00000080, // Enum type
1277-
StringLiteral = 0x00000100, // String literal type
1278-
TypeParameter = 0x00000200, // Type parameter
1279-
Class = 0x00000400, // Class
1280-
Interface = 0x00000800, // Interface
1281-
Reference = 0x00001000, // Generic type reference
1282-
Tuple = 0x00002000, // Tuple
1283-
Union = 0x00004000, // Union
1284-
Anonymous = 0x00008000, // Anonymous
1285-
FromSignature = 0x00010000, // Created for signature assignment check
1286-
ObjectLiteral = 0x00020000, // Originates in an object literal
1287-
ContainsUndefined = 0x00040000, // Type is or contains Undefined or Null type
1288-
ContainsLiteral = 0x00080000, // Type is or contains object literal type
1269+
Any = 0x00000001,
1270+
String = 0x00000002,
1271+
Number = 0x00000004,
1272+
Boolean = 0x00000008,
1273+
Void = 0x00000010,
1274+
Undefined = 0x00000020,
1275+
Null = 0x00000040,
1276+
Enum = 0x00000080, // Enum type
1277+
StringLiteral = 0x00000100, // String literal type
1278+
TypeParameter = 0x00000200, // Type parameter
1279+
Class = 0x00000400, // Class
1280+
Interface = 0x00000800, // Interface
1281+
Reference = 0x00001000, // Generic type reference
1282+
Tuple = 0x00002000, // Tuple
1283+
Union = 0x00004000, // Union
1284+
Anonymous = 0x00008000, // Anonymous
1285+
FromSignature = 0x00010000, // Created for signature assignment check
1286+
ObjectLiteral = 0x00020000, // Originates in an object literal
1287+
ContainsUndefinedOrNull = 0x00040000, // Type is or contains Undefined or Null type
1288+
ContainsObjectLiteral = 0x00080000, // Type is or contains object literal type
12891289

12901290
Intrinsic = Any | String | Number | Boolean | Void | Undefined | Null,
12911291
StringLike = String | StringLiteral,
12921292
NumberLike = Number | Enum,
12931293
ObjectType = Class | Interface | Reference | Tuple | Anonymous,
1294-
RequiresWidening = ContainsUndefined | ContainsLiteral
1294+
RequiresWidening = ContainsUndefinedOrNull | ContainsObjectLiteral
12951295
}
12961296

12971297
// Properties common to all types

0 commit comments

Comments
 (0)