Skip to content

Commit 647c41d

Browse files
authored
Fixed JSDoc get-only accessors to be serialized as const (#55444)
1 parent f996bab commit 647c41d

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9697,11 +9697,12 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
96979697
serializeAsFunctionNamespaceMerge(typeToSerialize, symbol, varName, isExportAssignmentCompatibleSymbolName ? ModifierFlags.None : ModifierFlags.Export);
96989698
}
96999699
else {
9700+
const flags = context.enclosingDeclaration?.kind === SyntaxKind.ModuleDeclaration && (!(symbol.flags & SymbolFlags.Accessor) || symbol.flags & SymbolFlags.SetAccessor) ? NodeFlags.Let : NodeFlags.Const;
97009701
const statement = factory.createVariableStatement(
97019702
/*modifiers*/ undefined,
97029703
factory.createVariableDeclarationList([
97039704
factory.createVariableDeclaration(varName, /*exclamationToken*/ undefined, serializeTypeForDeclaration(context, typeToSerialize, symbol, enclosingDeclaration, includePrivateSymbol, bundled)),
9704-
], context.enclosingDeclaration?.kind === SyntaxKind.ModuleDeclaration ? NodeFlags.Let : NodeFlags.Const),
9705+
], flags),
97059706
);
97069707
// Inlined JSON types exported with [module.]exports= will already emit an export=, so should use `declare`.
97079708
// Otherwise, the type itself should be exported.

tests/baselines/reference/accessorDeclarationEmitJs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const t3 = {
2727
//// [a.d.ts]
2828
export namespace t1 {
2929
let p: string;
30-
let getter: string;
30+
const getter: string;
3131
}
3232
export namespace t2 {
3333
let v: string;

0 commit comments

Comments
 (0)