Fixed JSDoc get-only accessors to be serialized as const (#55444)

This commit is contained in:
Mateusz Burzyński 2023-09-13 20:38:56 +02:00 committed by GitHub
parent f996bab056
commit 647c41d26e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 2 deletions

View File

@ -9697,11 +9697,12 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
serializeAsFunctionNamespaceMerge(typeToSerialize, symbol, varName, isExportAssignmentCompatibleSymbolName ? ModifierFlags.None : ModifierFlags.Export);
}
else {
const flags = context.enclosingDeclaration?.kind === SyntaxKind.ModuleDeclaration && (!(symbol.flags & SymbolFlags.Accessor) || symbol.flags & SymbolFlags.SetAccessor) ? NodeFlags.Let : NodeFlags.Const;
const statement = factory.createVariableStatement(
/*modifiers*/ undefined,
factory.createVariableDeclarationList([
factory.createVariableDeclaration(varName, /*exclamationToken*/ undefined, serializeTypeForDeclaration(context, typeToSerialize, symbol, enclosingDeclaration, includePrivateSymbol, bundled)),
], context.enclosingDeclaration?.kind === SyntaxKind.ModuleDeclaration ? NodeFlags.Let : NodeFlags.Const),
], flags),
);
// Inlined JSON types exported with [module.]exports= will already emit an export=, so should use `declare`.
// Otherwise, the type itself should be exported.

View File

@ -27,7 +27,7 @@ export const t3 = {
//// [a.d.ts]
export namespace t1 {
let p: string;
let getter: string;
const getter: string;
}
export namespace t2 {
let v: string;