Skip to content

Build your personal knowledge base with Trilium Notes

chore(share): fix tsc nagging about svg not existing on unknown

Panagiotis Papadopoulosa5a66a12e2ce
diff --git a/src/share/routes.ts b/src/share/routes.ts
index 932adfaacd..a2dbb6e0dd 100644
--- a/src/share/routes.ts
+++ b/src/share/routes.ts
@@ -115,7 +115,14 @@ function renderImageAttachment(image: SNote, res: Response, attachmentName: stri
svgString = content;
} else {
// backwards compatibility, before attachments, the SVG was stored in the main note content as a separate key
- const contentSvg = image.getJsonContentSafely()?.svg;
+ const possibleSvgContent = image.getJsonContentSafely();
+
+ const contentSvg = (typeof possibleSvgContent === "object"
+ && possibleSvgContent !== null
+ && "svg" in possibleSvgContent
+ && typeof possibleSvgContent.svg === "string")
+ ? possibleSvgContent.svg
+ : null;
if (contentSvg) {
svgString = contentSvg;