mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 12:51:30 -05:00
Handle numeric enums in mapped types + fix obscure crash
This commit is contained in:
@@ -6444,7 +6444,7 @@ namespace ts {
|
||||
for (const declaration of symbol.declarations) {
|
||||
if (declaration.kind === SyntaxKind.EnumDeclaration) {
|
||||
for (const member of (<EnumDeclaration>declaration).members) {
|
||||
const memberType = getFreshTypeOfLiteralType(getLiteralType(getEnumMemberValue(member)!, enumCount, getSymbolOfNode(member))); // TODO: GH#18217
|
||||
const memberType = getFreshTypeOfLiteralType(getLiteralType(getEnumMemberValue(member) || 0, enumCount, getSymbolOfNode(member)));
|
||||
getSymbolLinks(getSymbolOfNode(member)).declaredType = memberType;
|
||||
memberTypeList.push(getRegularTypeOfLiteralType(memberType));
|
||||
}
|
||||
@@ -7453,8 +7453,9 @@ namespace ts {
|
||||
else if (t.flags & (TypeFlags.Any | TypeFlags.String)) {
|
||||
stringIndexInfo = createIndexInfo(propType, !!(templateModifiers & MappedTypeModifiers.IncludeReadonly));
|
||||
}
|
||||
else if (t.flags & TypeFlags.Number) {
|
||||
numberIndexInfo = createIndexInfo(propType, !!(templateModifiers & MappedTypeModifiers.IncludeReadonly));
|
||||
else if (t.flags & (TypeFlags.Number | TypeFlags.Enum)) {
|
||||
numberIndexInfo = createIndexInfo(numberIndexInfo ? getUnionType([numberIndexInfo.type, propType]) : propType,
|
||||
!!(templateModifiers & MappedTypeModifiers.IncludeReadonly));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28440,9 +28441,9 @@ namespace ts {
|
||||
if (member.initializer) {
|
||||
return computeConstantValue(member);
|
||||
}
|
||||
// In ambient enum declarations that specify no const modifier, enum member declarations that omit
|
||||
// a value are considered computed members (as opposed to having auto-incremented values).
|
||||
if (member.parent.flags & NodeFlags.Ambient && !isEnumConst(member.parent)) {
|
||||
// In ambient non-const numeric enum declarations, enum members without initializers are
|
||||
// considered computed members (as opposed to having auto-incremented values).
|
||||
if (member.parent.flags & NodeFlags.Ambient && !isEnumConst(member.parent) && getEnumKind(getSymbolOfNode(member.parent)) === EnumKind.Numeric) {
|
||||
return undefined;
|
||||
}
|
||||
// If the member declaration specifies no value, the member is considered a constant enum member.
|
||||
|
||||
Reference in New Issue
Block a user