mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 12:51:30 -05:00
Merge pull request #31687 from microsoft/enumImplicitIndexSignatures
Implicit index signatures for enum object types
This commit is contained in:
@@ -7316,7 +7316,8 @@ namespace ts {
|
||||
stringIndexInfo = createIndexInfo(anyType, /*isReadonly*/ false);
|
||||
}
|
||||
}
|
||||
const numberIndexInfo = symbol.flags & SymbolFlags.Enum ? enumNumberIndexInfo : undefined;
|
||||
const numberIndexInfo = symbol.flags & SymbolFlags.Enum && (getDeclaredTypeOfSymbol(symbol).flags & TypeFlags.Enum ||
|
||||
some(type.properties, prop => !!(getTypeOfSymbol(prop).flags & TypeFlags.NumberLike))) ? enumNumberIndexInfo : undefined;
|
||||
setStructuredTypeMembers(type, members, emptyArray, emptyArray, stringIndexInfo, numberIndexInfo);
|
||||
// We resolve the members before computing the signatures because a signature may use
|
||||
// typeof with a qualified name expression that circularly references the type we are
|
||||
@@ -8194,6 +8195,9 @@ namespace ts {
|
||||
propTypes.push(getTypeOfSymbol(prop));
|
||||
}
|
||||
}
|
||||
if (kind === IndexKind.String) {
|
||||
append(propTypes, getIndexTypeOfType(type, IndexKind.Number));
|
||||
}
|
||||
if (propTypes.length) {
|
||||
return getUnionType(propTypes, UnionReduction.Subtype);
|
||||
}
|
||||
@@ -14615,7 +14619,7 @@ namespace ts {
|
||||
* with no call or construct signatures.
|
||||
*/
|
||||
function isObjectTypeWithInferableIndex(type: Type) {
|
||||
return type.symbol && (type.symbol.flags & (SymbolFlags.ObjectLiteral | SymbolFlags.TypeLiteral | SymbolFlags.ValueModule)) !== 0 &&
|
||||
return type.symbol && (type.symbol.flags & (SymbolFlags.ObjectLiteral | SymbolFlags.TypeLiteral | SymbolFlags.Enum | SymbolFlags.ValueModule)) !== 0 &&
|
||||
!typeHasCallOrConstructSignatures(type);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user