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
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.