Skip to content
Merged
Next Next commit
Declaration emit should retain unresolved computed names instead of e…
…lide
  • Loading branch information
weswigham committed May 3, 2024
commit 8d795343107f0c7f14c59f8eda5ba344ddd6d4bd
7 changes: 7 additions & 0 deletions src/compiler/transformers/declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,13 @@ export function transformDeclarations(context: TransformationContext) {
) {
context.addDiagnostic(createDiagnosticForNode(input, Diagnostics.Computed_properties_must_be_number_or_string_literals_variables_or_dotted_expressions_with_isolatedDeclarations));
}
if (isEntityNameExpression(input.name.expression)) {
// A.B.C that is not late bound - usually this means the expression did not resolve.
// Check the entity name, and copy the declaration, rather than elide it (there's
// probably a checker error in the input, but this is most likely the desired output).
checkEntityNameVisibility(input.name.expression, enclosingDeclaration);
return visitEachChild(input, visitDeclarationSubtree, context);
}
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//// [declarationTypeWithComputedName.ts] ////
import {Foo} from './a';

export type Bar = {
[Foo.A]: 1;
[Foo.B]: 2;
}
//// [declarationTypeWithComputedName.d.ts] ////
import { Foo } from './a';
export type Bar = {
[Foo.A]: 1;
[Foo.B]: 2;
};
8 changes: 8 additions & 0 deletions tests/cases/transpile/declarationTypeWithComputedName.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// @declaration: true
// @emitDeclarationOnly: true
import {Foo} from './a';

export type Bar = {
[Foo.A]: 1;
[Foo.B]: 2;
}