@@ -30142,7 +30142,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
30142
30142
const allPropertiesTable = strictNullChecks ? createSymbolTable() : undefined;
30143
30143
let propertiesTable = createSymbolTable();
30144
30144
let propertiesArray: Symbol[] = [];
30145
- let computedNameTypes: Type[] = [] ;
30145
+ let indexKeyTypes = new Set<Type>() ;
30146
30146
let spread: Type = emptyObjectType;
30147
30147
30148
30148
pushCachedContextualType(node);
@@ -30156,9 +30156,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
30156
30156
const isJSObjectLiteral = !contextualType && isInJavascript && !enumTag;
30157
30157
let objectFlags: ObjectFlags = freshObjectLiteralFlag;
30158
30158
let patternWithComputedProperties = false;
30159
- let hasComputedStringProperty = false;
30160
- let hasComputedNumberProperty = false;
30161
- let hasComputedSymbolProperty = false;
30162
30159
30163
30160
// Spreads may cause an early bail; ensure computed names are always checked (this is cached)
30164
30161
// As otherwise they may not be checked until exports for the type at this position are retrieved,
@@ -30255,10 +30252,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
30255
30252
spread = getSpreadType(spread, createObjectLiteralType(), node.symbol, objectFlags, inConstContext);
30256
30253
propertiesArray = [];
30257
30254
propertiesTable = createSymbolTable();
30258
- computedNameTypes = [];
30259
- hasComputedStringProperty = false;
30260
- hasComputedNumberProperty = false;
30261
- hasComputedSymbolProperty = false;
30255
+ indexKeyTypes = new Set();
30262
30256
}
30263
30257
const type = getReducedType(checkExpression(memberDecl.expression, checkMode & CheckMode.Inferential));
30264
30258
if (isValidSpreadType(type)) {
@@ -30290,17 +30284,17 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
30290
30284
30291
30285
if (computedNameType && !isTypeUsableAsPropertyName(computedNameType)) {
30292
30286
if (isPatternLiteralType(computedNameType)) {
30293
- computedNameTypes.push (computedNameType);
30287
+ indexKeyTypes.add (computedNameType);
30294
30288
}
30295
30289
else if (isTypeAssignableTo(computedNameType, stringNumberSymbolType)) {
30296
30290
if (isTypeAssignableTo(computedNameType, numberType)) {
30297
- hasComputedNumberProperty = true ;
30291
+ indexKeyTypes.add(numberType) ;
30298
30292
}
30299
30293
else if (isTypeAssignableTo(computedNameType, esSymbolType)) {
30300
- hasComputedSymbolProperty = true ;
30294
+ indexKeyTypes.add(esSymbolType) ;
30301
30295
}
30302
30296
else {
30303
- hasComputedStringProperty = true ;
30297
+ indexKeyTypes.add(stringType) ;
30304
30298
}
30305
30299
if (inDestructuringPattern) {
30306
30300
patternWithComputedProperties = true;
@@ -30355,9 +30349,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
30355
30349
spread = getSpreadType(spread, createObjectLiteralType(), node.symbol, objectFlags, inConstContext);
30356
30350
propertiesArray = [];
30357
30351
propertiesTable = createSymbolTable();
30358
- computedNameTypes = [];
30359
- hasComputedStringProperty = false;
30360
- hasComputedNumberProperty = false;
30352
+ indexKeyTypes = new Set();
30361
30353
}
30362
30354
// remap the raw emptyObjectType fed in at the top into a fresh empty object literal type, unique to this use site
30363
30355
return mapType(spread, t => t === emptyObjectType ? createObjectLiteralType() : t);
@@ -30366,14 +30358,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
30366
30358
return createObjectLiteralType();
30367
30359
30368
30360
function createObjectLiteralType() {
30369
- let indexInfos: IndexInfo[] = [];
30370
- for (const computedNameType of computedNameTypes) {
30371
- const indexInfo = getObjectLiteralIndexInfo(offset, propertiesArray, computedNameType, /*isReadonly*/ inConstContext);
30372
- indexInfos = appendIndexInfo(indexInfos, indexInfo, /*union*/ true);
30361
+ const indexInfos: IndexInfo[] = [];
30362
+ for (const keyType of indexKeyTypes) {
30363
+ indexInfos.push(getObjectLiteralIndexInfo(offset, propertiesArray, keyType, /*isReadonly*/ inConstContext));
30373
30364
}
30374
- if (hasComputedStringProperty) indexInfos.push(getObjectLiteralIndexInfo(offset, propertiesArray, stringType, /*isReadonly*/ inConstContext));
30375
- if (hasComputedNumberProperty) indexInfos.push(getObjectLiteralIndexInfo(offset, propertiesArray, numberType, /*isReadonly*/ inConstContext));
30376
- if (hasComputedSymbolProperty) indexInfos.push(getObjectLiteralIndexInfo(offset, propertiesArray, esSymbolType, /*isReadonly*/ inConstContext));
30377
30365
const result = createAnonymousType(node.symbol, propertiesTable, emptyArray, emptyArray, indexInfos);
30378
30366
result.objectFlags |= objectFlags | ObjectFlags.ObjectLiteral | ObjectFlags.ContainsObjectOrArrayLiteral;
30379
30367
if (isJSObjectLiteral) {
0 commit comments