mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-19 10:41:56 -05:00
Implement inferrable index signatures for enum types
This commit is contained in:
@@ -7299,7 +7299,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
|
||||
@@ -8161,6 +8162,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);
|
||||
}
|
||||
@@ -14498,7 +14502,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