From e69c2fa1945643ce1032938097a3495ffbf730ee Mon Sep 17 00:00:00 2001 From: formax68 Date: Sun, 17 May 2026 09:34:08 +0300 Subject: [PATCH] refactor(08-02): replace (window as any).moment with typed obsidian import (A1) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Per Amendment A1, the 5 (window as any).moment casts get replaced with the typed import { moment } from "obsidian" (obsidian.d.ts exports moment as typeof Moment). Removes 5 dead null-check branches that existed only because the cast was treated as nullable: 4 negative-shape (if (!moment) return) and 1 positive-shape (if (moment) { weekNum = ... } flattened to unconditional). - CalendarView.ts: 3 sites (checkDailyNoteForDate, renderWeekNumber, handleDailyNoteClick) — adds moment to existing obsidian import - EmbeddedCalendarView.ts: 1 site — adds moment to existing obsidian import - EmbeddedAgendaView.ts: 1 site — adds moment to existing obsidian import --- src/views/CalendarView.ts | 20 ++------------------ src/views/EmbeddedAgendaView.ts | 8 +------- src/views/EmbeddedCalendarView.ts | 8 +------- 3 files changed, 4 insertions(+), 32 deletions(-) diff --git a/src/views/CalendarView.ts b/src/views/CalendarView.ts index 91da901..5178837 100644 --- a/src/views/CalendarView.ts +++ b/src/views/CalendarView.ts @@ -1,4 +1,4 @@ -import { ItemView, WorkspaceLeaf, Notice, TFile, setIcon, MarkdownView, Menu, MenuItem } from "obsidian"; +import { ItemView, WorkspaceLeaf, Notice, TFile, setIcon, MarkdownView, Menu, MenuItem, moment } from "obsidian"; import { CalendarEvent } from "../services/CalendarService"; import MemoChron from "../main"; import { MEMOCHRON_VIEW_TYPE } from "../utils/constants"; @@ -156,11 +156,6 @@ export class CalendarView extends ItemView { } try { - const moment = (window as any).moment; - if (!moment) { - return false; - } - const momentDate = moment(date); const allDailyNotes = getAllDailyNotes(); const dailyNote = getDailyNote(momentDate, allDailyNotes); @@ -551,12 +546,7 @@ export class CalendarView extends ItemView { } private renderWeekNumber(grid: HTMLElement, date: Date) { - const moment = (window as any).moment; - let weekNum = "?"; - - if (moment) { - weekNum = String(moment(date).week()); - } + const weekNum = String(moment(date).week()); grid.createEl("div", { cls: "memochron-week-number", @@ -801,12 +791,6 @@ export class CalendarView extends ItemView { } // Use moment for date handling (same as Obsidian's daily notes) - const moment = (window as any).moment; - if (!moment) { - new Notice("Moment.js is not available"); - return; - } - const momentDate = moment(date); // Get all daily notes diff --git a/src/views/EmbeddedAgendaView.ts b/src/views/EmbeddedAgendaView.ts index fe82e04..989e74d 100644 --- a/src/views/EmbeddedAgendaView.ts +++ b/src/views/EmbeddedAgendaView.ts @@ -1,4 +1,4 @@ -import { MarkdownRenderChild, MarkdownView, Notice, setIcon, TFile } from "obsidian"; +import { MarkdownRenderChild, MarkdownView, Notice, setIcon, TFile, moment } from "obsidian"; import MemoChron from "../main"; import { parseDate, @@ -376,12 +376,6 @@ export class EmbeddedAgendaView extends MarkdownRenderChild { return; } - const moment = (window as any).moment; - if (!moment) { - new Notice("Moment.js is not available"); - return; - } - const momentDate = moment(date); const allDailyNotes = getAllDailyNotes(); let dailyNote = getDailyNote(momentDate, allDailyNotes); diff --git a/src/views/EmbeddedCalendarView.ts b/src/views/EmbeddedCalendarView.ts index ab518d2..a8b7671 100644 --- a/src/views/EmbeddedCalendarView.ts +++ b/src/views/EmbeddedCalendarView.ts @@ -1,4 +1,4 @@ -import { MarkdownRenderChild, Notice, TFile } from "obsidian"; +import { MarkdownRenderChild, Notice, TFile, moment } from "obsidian"; import MemoChron from "../main"; import { renderCalendarGrid, @@ -220,12 +220,6 @@ export class EmbeddedCalendarView extends MarkdownRenderChild { } // Use moment for date handling (same as Obsidian's daily notes) - const moment = (window as any).moment; - if (!moment) { - new Notice("Moment.js is not available"); - return; - } - const momentDate = moment(date); // Get all daily notes