Skip to content

Commit 2e99438

Browse files
committed
Handle numeric enums in mapped types + fix obscure crash
1 parent 9da0524 commit 2e99438

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/compiler/checker.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6444,7 +6444,7 @@ namespace ts {
64446444
for (const declaration of symbol.declarations) {
64456445
if (declaration.kind === SyntaxKind.EnumDeclaration) {
64466446
for (const member of (<EnumDeclaration>declaration).members) {
6447-
const memberType = getFreshTypeOfLiteralType(getLiteralType(getEnumMemberValue(member)!, enumCount, getSymbolOfNode(member))); // TODO: GH#18217
6447+
const memberType = getFreshTypeOfLiteralType(getLiteralType(getEnumMemberValue(member) || 0, enumCount, getSymbolOfNode(member)));
64486448
getSymbolLinks(getSymbolOfNode(member)).declaredType = memberType;
64496449
memberTypeList.push(getRegularTypeOfLiteralType(memberType));
64506450
}
@@ -7453,8 +7453,9 @@ namespace ts {
74537453
else if (t.flags & (TypeFlags.Any | TypeFlags.String)) {
74547454
stringIndexInfo = createIndexInfo(propType, !!(templateModifiers & MappedTypeModifiers.IncludeReadonly));
74557455
}
7456-
else if (t.flags & TypeFlags.Number) {
7457-
numberIndexInfo = createIndexInfo(propType, !!(templateModifiers & MappedTypeModifiers.IncludeReadonly));
7456+
else if (t.flags & (TypeFlags.Number | TypeFlags.Enum)) {
7457+
numberIndexInfo = createIndexInfo(numberIndexInfo ? getUnionType([numberIndexInfo.type, propType]) : propType,
7458+
!!(templateModifiers & MappedTypeModifiers.IncludeReadonly));
74587459
}
74597460
}
74607461
}
@@ -28440,9 +28441,9 @@ namespace ts {
2844028441
if (member.initializer) {
2844128442
return computeConstantValue(member);
2844228443
}
28443-
// In ambient enum declarations that specify no const modifier, enum member declarations that omit
28444-
// a value are considered computed members (as opposed to having auto-incremented values).
28445-
if (member.parent.flags & NodeFlags.Ambient && !isEnumConst(member.parent)) {
28444+
// In ambient non-const numeric enum declarations, enum members without initializers are
28445+
// considered computed members (as opposed to having auto-incremented values).
28446+
if (member.parent.flags & NodeFlags.Ambient && !isEnumConst(member.parent) && getEnumKind(getSymbolOfNode(member.parent)) === EnumKind.Numeric) {
2844628447
return undefined;
2844728448
}
2844828449
// If the member declaration specifies no value, the member is considered a constant enum member.

0 commit comments

Comments
 (0)