From e3d9b16f6ebcc1e10d3efb810f3b5e7a344e7bb2 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 24 May 2026 14:56:45 +0000 Subject: [PATCH] refactor: use PageData type for page data assertions Replaced anonymous object casts with the defined `PageData` type in `app/sitemap.ts` and `app/docs/layout.tsx`. Removed redundant null-coalescing fallbacks `?? {}` in `app/sitemap.ts` as the `PageData` type supports optional properties and subsequent logic uses optional chaining. Imported `PageData` in `app/docs/layout.tsx` to maintain type consistency across the codebase. Co-authored-by: longsizhuo <114939201+longsizhuo@users.noreply.github.com> --- app/docs/layout.tsx | 3 ++- app/sitemap.ts | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/docs/layout.tsx b/app/docs/layout.tsx index 4e50948e..0d07b144 100644 --- a/app/docs/layout.tsx +++ b/app/docs/layout.tsx @@ -7,6 +7,7 @@ import type { PageTree } from "fumadocs-core/server"; import { CopyTracking } from "@/app/components/CopyTracking"; import { DocsPageViewTracker } from "@/app/components/DocsPageViewTracker"; import { cookies } from "next/headers"; +import { type PageData } from "@/app/types/doc"; type Locale = "zh" | "en"; type SourcePage = ReturnType[number]; @@ -77,7 +78,7 @@ function chooseVariant(variants: SourcePage[], locale: Locale): SourcePage { const originalMatching = variants.find((p) => { const { suffix } = stripLocaleSuffix(p.slugs); if (suffix !== null) return false; - const lang = (p.data as { lang?: string }).lang; + const lang = (p.data as PageData).lang; return lang === locale; }); if (originalMatching) return originalMatching; diff --git a/app/sitemap.ts b/app/sitemap.ts index 262722b0..2b168ce3 100644 --- a/app/sitemap.ts +++ b/app/sitemap.ts @@ -127,8 +127,8 @@ function buildDocsEntry(page: SourcePage): MetadataRoute.Sitemap[number] { * @returns {Date | undefined} 解析后的 Date 对象,如果找不到或无效则返回 undefined。 */ function extractDateFromPage(page: SourcePage): Date | undefined { - // (FIX) 使用我们定义的 PageData 类型,而不是 'as' 一个匿名对象 - const data = (page.data ?? {}) as PageData; + // 使用我们定义的 PageData 类型 + const data = page.data as PageData; const candidates: DateLike[] = [ data?.updatedAt, @@ -183,8 +183,8 @@ function sanitizeSlugPath(slugs: string[]): string { * @returns {boolean} 如果是草稿或隐藏,返回 true。 */ function isDraftOrHidden(page: SourcePage): boolean { - // [BUILD 修复] 使用我们定义的 PageData 类型来代替 'any' - const d = (page.data ?? {}) as PageData; + // 使用我们定义的 PageData 类型 + const d = page.data as PageData; // 检查顶层或 'frontmatter' 嵌套下的 'draft' 或 'hidden' 标志 return !!(