@@ -1618,9 +1618,12 @@ namespace ts {
1618
1618
return <ResolvedType>type;
1619
1619
}
1620
1620
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);
1624
1627
}
1625
1628
1626
1629
function forEachSymbolTableInScope<T>(enclosingDeclaration: Node, callback: (symbolTable: SymbolTable) => T): T {
@@ -3177,7 +3180,9 @@ namespace ts {
3177
3180
if (includePatternInType) {
3178
3181
result.pattern = pattern;
3179
3182
}
3180
- result.inObjectLiteralPatternWithComputedProperties = hasComputedProperties;
3183
+ if (hasComputedProperties) {
3184
+ result.inObjectLiteralPatternWithComputedProperties = hasComputedProperties;
3185
+ }
3181
3186
return result;
3182
3187
}
3183
3188
@@ -4413,7 +4418,7 @@ namespace ts {
4413
4418
* boolean, and symbol primitive types, return the corresponding object types. Otherwise return the
4414
4419
* type itself. Note that the apparent type of a union type is the union type itself.
4415
4420
*/
4416
- function getApparentType(type: Type): ObjectType {
4421
+ function getApparentType(type: Type): Type {
4417
4422
if (type.flags & TypeFlags.TypeParameter) {
4418
4423
type = getApparentTypeOfTypeParameter(<TypeParameter>type);
4419
4424
}
@@ -5920,8 +5925,7 @@ namespace ts {
5920
5925
mapper.instantiations = [];
5921
5926
}
5922
5927
// 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);
5925
5929
result.target = type;
5926
5930
result.mapper = mapper;
5927
5931
result.aliasSymbol = type.aliasSymbol;
@@ -5993,7 +5997,7 @@ namespace ts {
5993
5997
// instantiation.
5994
5998
return type.symbol &&
5995
5999
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)) ?
5997
6001
instantiateAnonymousType(<AnonymousType>type, mapper) : type;
5998
6002
}
5999
6003
if (type.flags & TypeFlags.Reference) {
@@ -6473,7 +6477,7 @@ namespace ts {
6473
6477
6474
6478
if (isSimpleTypeRelatedTo(source, target, relation, reportErrors ? reportError : undefined)) return Ternary.True;
6475
6479
6476
- if (source.flags & TypeFlags.ObjectLiteral && source.flags & TypeFlags.FreshLiteral) {
6480
+ if (source.flags & TypeFlags.ObjectType && (source as ObjectType).isObjectLiteral && source.flags & TypeFlags.FreshLiteral) {
6477
6481
if (hasExcessProperties(<FreshObjectLiteralType>source, target, reportErrors)) {
6478
6482
if (reportErrors) {
6479
6483
reportRelationError(headMessage, source, target);
@@ -6647,7 +6651,8 @@ namespace ts {
6647
6651
}
6648
6652
6649
6653
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)) {
6651
6656
for (const prop of getPropertiesOfObjectType(source)) {
6652
6657
if (!isKnownProperty(target, prop.name)) {
6653
6658
if (reportErrors) {
@@ -6841,7 +6846,7 @@ namespace ts {
6841
6846
}
6842
6847
let result = Ternary.True;
6843
6848
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 );
6845
6850
for (const targetProp of properties) {
6846
6851
const sourceProp = getPropertyOfType(source, targetProp.name);
6847
6852
@@ -7141,12 +7146,12 @@ namespace ts {
7141
7146
// some level beyond that.
7142
7147
function isDeeplyNestedGeneric(type: Type, stack: Type[], depth: number): boolean {
7143
7148
// 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) {
7145
7150
const symbol = type.symbol;
7146
7151
let count = 0;
7147
7152
for (let i = 0; i < depth; i++) {
7148
7153
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) {
7150
7155
count++;
7151
7156
if (count >= 5) return true;
7152
7157
}
@@ -7480,7 +7485,7 @@ namespace ts {
7480
7485
* Leave signatures alone since they are not subject to the check.
7481
7486
*/
7482
7487
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)) {
7484
7489
return type;
7485
7490
}
7486
7491
const regularType = (<FreshObjectLiteralType>type).regularType;
@@ -7495,7 +7500,8 @@ namespace ts {
7495
7500
resolved.callSignatures,
7496
7501
resolved.constructSignatures,
7497
7502
resolved.stringIndexInfo,
7498
- resolved.numberIndexInfo);
7503
+ resolved.numberIndexInfo,
7504
+ resolved.isObjectLiteral);
7499
7505
regularNew.flags = resolved.flags & ~TypeFlags.FreshLiteral;
7500
7506
(<FreshObjectLiteralType>type).regularType = regularNew;
7501
7507
return regularNew;
@@ -7510,7 +7516,8 @@ namespace ts {
7510
7516
const numberIndexInfo = getIndexInfoOfType(type, IndexKind.Number);
7511
7517
return createAnonymousType(type.symbol, members, emptyArray, emptyArray,
7512
7518
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);
7514
7521
}
7515
7522
7516
7523
function getWidenedConstituentType(type: Type): Type {
@@ -7522,7 +7529,8 @@ namespace ts {
7522
7529
if (type.flags & TypeFlags.Nullable) {
7523
7530
return anyType;
7524
7531
}
7525
- if (type.flags & TypeFlags.ObjectLiteral) {
7532
+ // if (type.flags & TypeFlags.ObjectLiteral) {
7533
+ if (type.flags & TypeFlags.ObjectType && (type as ObjectType).isObjectLiteral) {
7526
7534
return getWidenedTypeOfObjectLiteral(type);
7527
7535
}
7528
7536
if (type.flags & TypeFlags.Union) {
@@ -7562,7 +7570,7 @@ namespace ts {
7562
7570
}
7563
7571
}
7564
7572
}
7565
- if (type.flags & TypeFlags.ObjectLiteral ) {
7573
+ if (type.flags & TypeFlags.ObjectType && (type as ObjectType).isObjectLiteral ) {
7566
7574
for (const p of getPropertiesOfObjectType(type)) {
7567
7575
const t = getTypeOfSymbol(p);
7568
7576
if (t.flags & TypeFlags.ContainsWideningType) {
@@ -9938,7 +9946,7 @@ namespace ts {
9938
9946
9939
9947
// Return the contextual type for a given expression node. During overload resolution, a contextual type may temporarily
9940
9948
// be "pushed" onto a node using the contextualType property.
9941
- function getApparentTypeOfContextualType(node: Expression): ObjectType {
9949
+ function getApparentTypeOfContextualType(node: Expression): Type {
9942
9950
const type = getContextualType(node);
9943
9951
return type && getApparentType(type);
9944
9952
}
@@ -10307,7 +10315,8 @@ namespace ts {
10307
10315
patternWithComputedProperties = true;
10308
10316
}
10309
10317
}
10310
- else if (contextualTypeHasPattern && !contextualType.inObjectLiteralPatternWithComputedProperties) {
10318
+ else if (contextualTypeHasPattern &&
10319
+ !(contextualType.flags & TypeFlags.ObjectType && (contextualType as ObjectType).inObjectLiteralPatternWithComputedProperties)) {
10311
10320
// If object literal is contextually typed by the implied type of a binding pattern, and if the
10312
10321
// binding pattern specifies a default value for the property, make the property optional.
10313
10322
const impliedProp = getPropertyOfType(contextualType, member.name);
@@ -10370,10 +10379,12 @@ namespace ts {
10370
10379
10371
10380
const stringIndexInfo = hasComputedStringProperty ? getObjectLiteralIndexInfo(node, propertiesArray, IndexKind.String) : undefined;
10372
10381
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 );
10374
10383
const freshObjectLiteralFlag = compilerOptions.suppressExcessPropertyErrors ? 0 : TypeFlags.FreshLiteral;
10375
10384
result.flags |= TypeFlags.ObjectLiteral | TypeFlags.ContainsObjectLiteral | freshObjectLiteralFlag | (typeFlags & TypeFlags.PropagatingFlags);
10376
- result.inObjectLiteralPatternWithComputedProperties = patternWithComputedProperties;
10385
+ if (patternWithComputedProperties) {
10386
+ result.inObjectLiteralPatternWithComputedProperties = patternWithComputedProperties;
10387
+ }
10377
10388
if (inDestructuringPattern) {
10378
10389
result.pattern = node;
10379
10390
}
0 commit comments