Centralize PageData type and refactor page.data casts#323
Conversation
- Created `app/types/doc.ts` to host shared `PageData` and `DateLike` types. - Updated `app/sitemap.ts` to use imported types instead of local definitions. - Refactored `lib/search-index.ts` to use `PageData` instead of `PageDataShape`. - Updated `app/docs/[...slug]/page.tsx` to use `PageData` for `page.data` casts, simplifying the code. - Ensured consistent property access across the codebase. Co-authored-by: longsizhuo <114939201+longsizhuo@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Pull request overview
This PR centralizes the typing for Fumadocs page.data into app/types/doc.ts and updates call sites to use the shared PageData/DateLike types instead of local/anonymous casts, improving consistency across sitemap generation, search indexing, and docs rendering.
Changes:
- Add
app/types/doc.tsto define sharedPageDataandDateLike. - Refactor
lib/search-index.tsto use the centralizedPageDatatype (includingstructuredData/loadhandling). - Remove duplicate
PageData/DateLikedefinitions fromapp/sitemap.tsand updateapp/docs/[...slug]/page.tsxcasts to use the shared type.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| app/types/doc.ts | Introduces centralized PageData/DateLike definitions for Fumadocs page.data. |
| lib/search-index.ts | Replaces local page data shape typing with the shared PageData. |
| app/sitemap.ts | Removes duplicated local type definitions and imports shared types. |
| app/docs/[...slug]/page.tsx | Uses shared PageData for lang/docId access instead of ad-hoc casts. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| [key: string]: any; | ||
| }; | ||
| /** | ||
| * 允许通过索引访问其他动态属性 | ||
| */ | ||
| [key: string]: any; |
There was a problem hiding this comment.
PageData/frontmatter use [key: string]: any, which effectively opts out of type safety for all extra metadata and undermines the PR’s goal of improving typing. Consider using unknown for the index signatures (or replacing them with an explicit metadata?: Record<string, unknown>), so callers must narrow/validate before use while keeping named fields strongly typed.
| [key: string]: any; | |
| }; | |
| /** | |
| * 允许通过索引访问其他动态属性 | |
| */ | |
| [key: string]: any; | |
| [key: string]: unknown; | |
| }; | |
| /** | |
| * 允许通过索引访问其他动态属性 | |
| */ | |
| [key: string]: unknown; |
PR #323 build 挂在 lint:app/types/doc.ts 两处 [key: string]: any 触发 @typescript-eslint/no-explicit-any error。 修法权衡 - frontmatter 嵌套对象:any → unknown(真的动态字段,调用方需显式 narrow) - PageData 顶层:直接干掉 [key: string]: any 索引签名 为什么不是 unknown:试过 unknown,所有 5 处 `as PageData` cast 都炸 TS2352 "neither type sufficiently overlaps" —— Fumadocs 的 page.data 由 zod DocOut 推出,本身没有 index signature;PageData 顶层挂一个就跟 zod 类型形成"对方有但我没有"的不兼容。要么所有 cast 改 `as unknown as PageData` (等于把 escape hatch 散到 5 处),要么干脆不挂顶层 index signature (escape hatch 收窄到一处 frontmatter 子对象)。后者更干净。 调用方(page.tsx / sitemap.ts / search-index.ts)的现有访问字段 (docId / lang / draft / hidden / DateLike 候选)都已经在 PageData 顶层 显式声明,去掉 index signature 不影响任何现有代码,tsc + lint 均过。 Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
This PR centralizes the
PageDataandDateLiketype definitions into a single file (app/types/doc.ts) and refactors various parts of the codebase that were using anonymous object casts forpage.data. This improves type safety and maintainability by ensuring that all components and utilities interacting with Fumadocs page data use a consistent and well-defined interface.Key changes:
app/types/doc.tswhich defines thePageDatainterface, including common frontmatter fields, Fumadocs-specific fields, and support for arbitrary metadata.app/sitemap.tsand replaced anonymous casts with the newPageDatatype.PageDataShapeinterface inlib/search-index.tswith the centralizedPageDatatype.app/docs/[...slug]/page.tsxto usePageData, removing redundant inline type definitions during casting.PR created automatically by Jules for task 1321556333293577153 started by @longsizhuo