@@ -1618,9 +1618,12 @@ namespace ts {
16181618 return <ResolvedType>type;
16191619 }
16201620
1621- function createAnonymousType(symbol: Symbol, members: SymbolTable, callSignatures: Signature[], constructSignatures: Signature[], stringIndexInfo: IndexInfo, numberIndexInfo: IndexInfo): ResolvedType {
1622- return setObjectTypeMembers(createObjectType(TypeFlags.Anonymous, symbol),
1623- members, callSignatures, constructSignatures, stringIndexInfo, numberIndexInfo);
1621+ function createAnonymousType(symbol: Symbol, members: SymbolTable, callSignatures: Signature[], constructSignatures: Signature[], stringIndexInfo: IndexInfo, numberIndexInfo: IndexInfo, isObjectLiteral?: boolean): ResolvedType {
1622+ const t = createObjectType(TypeFlags.Anonymous, symbol);
1623+ if (isObjectLiteral) {
1624+ t.isObjectLiteral = true;
1625+ }
1626+ return setObjectTypeMembers(t, members, callSignatures, constructSignatures, stringIndexInfo, numberIndexInfo);
16241627 }
16251628
16261629 function forEachSymbolTableInScope<T>(enclosingDeclaration: Node, callback: (symbolTable: SymbolTable) => T): T {
@@ -3177,7 +3180,9 @@ namespace ts {
31773180 if (includePatternInType) {
31783181 result.pattern = pattern;
31793182 }
3180- result.inObjectLiteralPatternWithComputedProperties = hasComputedProperties;
3183+ if (hasComputedProperties) {
3184+ result.inObjectLiteralPatternWithComputedProperties = hasComputedProperties;
3185+ }
31813186 return result;
31823187 }
31833188
@@ -4413,7 +4418,7 @@ namespace ts {
44134418 * boolean, and symbol primitive types, return the corresponding object types. Otherwise return the
44144419 * type itself. Note that the apparent type of a union type is the union type itself.
44154420 */
4416- function getApparentType(type: Type): ObjectType {
4421+ function getApparentType(type: Type): Type {
44174422 if (type.flags & TypeFlags.TypeParameter) {
44184423 type = getApparentTypeOfTypeParameter(<TypeParameter>type);
44194424 }
@@ -5920,8 +5925,7 @@ namespace ts {
59205925 mapper.instantiations = [];
59215926 }
59225927 // Mark the anonymous type as instantiated such that our infinite instantiation detection logic can recognize it
5923- const result = <AnonymousType>createObjectType(TypeFlags.Anonymous, type.symbol);
5924- result.isInstantiated = true;
5928+ const result = <AnonymousType>createObjectType(TypeFlags.Anonymous | TypeFlags.Instantiated, type.symbol);
59255929 result.target = type;
59265930 result.mapper = mapper;
59275931 result.aliasSymbol = type.aliasSymbol;
@@ -5993,7 +5997,7 @@ namespace ts {
59935997 // instantiation.
59945998 return type.symbol &&
59955999 type.symbol.flags & (SymbolFlags.Function | SymbolFlags.Method | SymbolFlags.Class | SymbolFlags.TypeLiteral | SymbolFlags.ObjectLiteral) &&
5996- (( type as AnonymousType).isInstantiated || isSymbolInScopeOfMappedTypeParameter(type.symbol, mapper)) ?
6000+ (type.flags & TypeFlags.Instantiated || isSymbolInScopeOfMappedTypeParameter(type.symbol, mapper)) ?
59976001 instantiateAnonymousType(<AnonymousType>type, mapper) : type;
59986002 }
59996003 if (type.flags & TypeFlags.Reference) {
@@ -6473,7 +6477,7 @@ namespace ts {
64736477
64746478 if (isSimpleTypeRelatedTo(source, target, relation, reportErrors ? reportError : undefined)) return Ternary.True;
64756479
6476- if (source.flags & TypeFlags.ObjectLiteral && source.flags & TypeFlags.FreshLiteral) {
6480+ if (source.flags & TypeFlags.ObjectType && (source as ObjectType).isObjectLiteral && source.flags & TypeFlags.FreshLiteral) {
64776481 if (hasExcessProperties(<FreshObjectLiteralType>source, target, reportErrors)) {
64786482 if (reportErrors) {
64796483 reportRelationError(headMessage, source, target);
@@ -6647,7 +6651,8 @@ namespace ts {
66476651 }
66486652
66496653 function hasExcessProperties(source: FreshObjectLiteralType, target: Type, reportErrors: boolean): boolean {
6650- if (maybeTypeOfKind(target, TypeFlags.ObjectType) && !(target as ObjectType).inObjectLiteralPatternWithComputedProperties) {
6654+ if (maybeTypeOfKind(target, TypeFlags.ObjectType) &&
6655+ (!(target.flags & TypeFlags.ObjectType) || !(target as ObjectType).inObjectLiteralPatternWithComputedProperties)) {
66516656 for (const prop of getPropertiesOfObjectType(source)) {
66526657 if (!isKnownProperty(target, prop.name)) {
66536658 if (reportErrors) {
@@ -6841,7 +6846,7 @@ namespace ts {
68416846 }
68426847 let result = Ternary.True;
68436848 const properties = getPropertiesOfObjectType(target);
6844- const requireOptionalProperties = relation === subtypeRelation && !(source.flags & TypeFlags.ObjectLiteral );
6849+ const requireOptionalProperties = relation === subtypeRelation && !(source.flags & TypeFlags.ObjectType && (source as ObjectType).isObjectLiteral );
68456850 for (const targetProp of properties) {
68466851 const sourceProp = getPropertyOfType(source, targetProp.name);
68476852
@@ -7141,12 +7146,12 @@ namespace ts {
71417146 // some level beyond that.
71427147 function isDeeplyNestedGeneric(type: Type, stack: Type[], depth: number): boolean {
71437148 // We track type references (created by createTypeReference) and instantiated types (created by instantiateType)
7144- if (( type.flags & TypeFlags.Reference || type.flags & TypeFlags.Anonymous && (type as AnonymousType).isInstantiated ) && depth >= 5) {
7149+ if (type.flags & ( TypeFlags.Reference | TypeFlags.Instantiated ) && depth >= 5) {
71457150 const symbol = type.symbol;
71467151 let count = 0;
71477152 for (let i = 0; i < depth; i++) {
71487153 const t = stack[i];
7149- if (( t.flags & TypeFlags.Reference || t.flags & TypeFlags.Anonymous && (t as AnonymousType).isInstantiated ) && t.symbol === symbol) {
7154+ if (t.flags & ( TypeFlags.Reference | TypeFlags.Instantiated ) && t.symbol === symbol) {
71507155 count++;
71517156 if (count >= 5) return true;
71527157 }
@@ -7480,7 +7485,7 @@ namespace ts {
74807485 * Leave signatures alone since they are not subject to the check.
74817486 */
74827487 function getRegularTypeOfObjectLiteral(type: Type): Type {
7483- if (!(type.flags & TypeFlags.ObjectLiteral && type.flags & TypeFlags.FreshLiteral)) {
7488+ if (!(type.flags & TypeFlags.ObjectType && (type as ObjectType).isObjectLiteral && type.flags & TypeFlags.FreshLiteral)) {
74847489 return type;
74857490 }
74867491 const regularType = (<FreshObjectLiteralType>type).regularType;
@@ -7495,7 +7500,8 @@ namespace ts {
74957500 resolved.callSignatures,
74967501 resolved.constructSignatures,
74977502 resolved.stringIndexInfo,
7498- resolved.numberIndexInfo);
7503+ resolved.numberIndexInfo,
7504+ resolved.isObjectLiteral);
74997505 regularNew.flags = resolved.flags & ~TypeFlags.FreshLiteral;
75007506 (<FreshObjectLiteralType>type).regularType = regularNew;
75017507 return regularNew;
@@ -7510,7 +7516,8 @@ namespace ts {
75107516 const numberIndexInfo = getIndexInfoOfType(type, IndexKind.Number);
75117517 return createAnonymousType(type.symbol, members, emptyArray, emptyArray,
75127518 stringIndexInfo && createIndexInfo(getWidenedType(stringIndexInfo.type), stringIndexInfo.isReadonly),
7513- numberIndexInfo && createIndexInfo(getWidenedType(numberIndexInfo.type), numberIndexInfo.isReadonly));
7519+ numberIndexInfo && createIndexInfo(getWidenedType(numberIndexInfo.type), numberIndexInfo.isReadonly),
7520+ (type as ObjectType).isObjectLiteral);
75147521 }
75157522
75167523 function getWidenedConstituentType(type: Type): Type {
@@ -7522,7 +7529,8 @@ namespace ts {
75227529 if (type.flags & TypeFlags.Nullable) {
75237530 return anyType;
75247531 }
7525- if (type.flags & TypeFlags.ObjectLiteral) {
7532+ // if (type.flags & TypeFlags.ObjectLiteral) {
7533+ if (type.flags & TypeFlags.ObjectType && (type as ObjectType).isObjectLiteral) {
75267534 return getWidenedTypeOfObjectLiteral(type);
75277535 }
75287536 if (type.flags & TypeFlags.Union) {
@@ -7562,7 +7570,7 @@ namespace ts {
75627570 }
75637571 }
75647572 }
7565- if (type.flags & TypeFlags.ObjectLiteral ) {
7573+ if (type.flags & TypeFlags.ObjectType && (type as ObjectType).isObjectLiteral ) {
75667574 for (const p of getPropertiesOfObjectType(type)) {
75677575 const t = getTypeOfSymbol(p);
75687576 if (t.flags & TypeFlags.ContainsWideningType) {
@@ -9938,7 +9946,7 @@ namespace ts {
99389946
99399947 // Return the contextual type for a given expression node. During overload resolution, a contextual type may temporarily
99409948 // be "pushed" onto a node using the contextualType property.
9941- function getApparentTypeOfContextualType(node: Expression): ObjectType {
9949+ function getApparentTypeOfContextualType(node: Expression): Type {
99429950 const type = getContextualType(node);
99439951 return type && getApparentType(type);
99449952 }
@@ -10307,7 +10315,8 @@ namespace ts {
1030710315 patternWithComputedProperties = true;
1030810316 }
1030910317 }
10310- else if (contextualTypeHasPattern && !contextualType.inObjectLiteralPatternWithComputedProperties) {
10318+ else if (contextualTypeHasPattern &&
10319+ !(contextualType.flags & TypeFlags.ObjectType && (contextualType as ObjectType).inObjectLiteralPatternWithComputedProperties)) {
1031110320 // If object literal is contextually typed by the implied type of a binding pattern, and if the
1031210321 // binding pattern specifies a default value for the property, make the property optional.
1031310322 const impliedProp = getPropertyOfType(contextualType, member.name);
@@ -10370,10 +10379,12 @@ namespace ts {
1037010379
1037110380 const stringIndexInfo = hasComputedStringProperty ? getObjectLiteralIndexInfo(node, propertiesArray, IndexKind.String) : undefined;
1037210381 const numberIndexInfo = hasComputedNumberProperty ? getObjectLiteralIndexInfo(node, propertiesArray, IndexKind.Number) : undefined;
10373- const result = createAnonymousType(node.symbol, propertiesTable, emptyArray, emptyArray, stringIndexInfo, numberIndexInfo);
10382+ const result = createAnonymousType(node.symbol, propertiesTable, emptyArray, emptyArray, stringIndexInfo, numberIndexInfo, /*isObjectLiteral*/ true );
1037410383 const freshObjectLiteralFlag = compilerOptions.suppressExcessPropertyErrors ? 0 : TypeFlags.FreshLiteral;
1037510384 result.flags |= TypeFlags.ObjectLiteral | TypeFlags.ContainsObjectLiteral | freshObjectLiteralFlag | (typeFlags & TypeFlags.PropagatingFlags);
10376- result.inObjectLiteralPatternWithComputedProperties = patternWithComputedProperties;
10385+ if (patternWithComputedProperties) {
10386+ result.inObjectLiteralPatternWithComputedProperties = patternWithComputedProperties;
10387+ }
1037710388 if (inDestructuringPattern) {
1037810389 result.pattern = node;
1037910390 }
0 commit comments