@@ -33885,7 +33885,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
33885
33885
}
33886
33886
33887
33887
// TODO(jakebailey): write test case
33888
- if (isConstEnumObjectType(objectType) && !isStringLiteralLike(indexExpression) && !isPreservedConstEnum( objectType)) {
33888
+ if (isConstEnumObjectType(objectType) && !isStringLiteralLike(indexExpression) && !isPreservedConstEnumUse(node, objectType)) {
33889
33889
error(indexExpression, Diagnostics.A_const_enum_member_can_only_be_accessed_using_a_string_literal);
33890
33890
return errorType;
33891
33891
}
@@ -39817,7 +39817,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
39817
39817
(node.parent.kind === SyntaxKind.ExportSpecifier); // We allow reexporting const enums
39818
39818
39819
39819
if (!ok || getIsolatedModules(compilerOptions)) {
39820
- if (!isPreservedConstEnum( type)) {
39820
+ if (!isPreservedConstEnumUse(node, type)) {
39821
39821
if (!ok) {
39822
39822
// TODO(jakebailey): write negative test case
39823
39823
// TODO(jakebailey): make error message mention const enum preservation
@@ -39829,12 +39829,15 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
39829
39829
}
39830
39830
}
39831
39831
39832
- function isPreservedConstEnum(type : Type) {
39833
- Debug.assert(!!(type .symbol.flags & SymbolFlags.ConstEnum));
39834
- const constEnumDeclaration = type .symbol.valueDeclaration as EnumDeclaration;
39832
+ function isPreservedConstEnumUse(use: Node, enumType : Type) {
39833
+ Debug.assert(!!(enumType .symbol.flags & SymbolFlags.ConstEnum));
39834
+ const constEnumDeclaration = enumType .symbol.valueDeclaration as EnumDeclaration;
39835
39835
const otherFile = getSourceFileOfNode(constEnumDeclaration);
39836
39836
if (!otherFile.isDeclarationFile) {
39837
39837
// This file can only have come from the current project.
39838
+ if (constEnumDeclaration.flags & NodeFlags.Ambient && !isValidTypeOnlyAliasUseSite(use)) {
39839
+ return false
39840
+ }
39838
39841
return shouldPreserveConstEnums(compilerOptions);
39839
39842
}
39840
39843
const redirect = host.getRedirectReferenceForResolutionFromSourceOfProject(otherFile.resolvedPath);
0 commit comments