Skip to content

Commit 0221ac9

Browse files
fix(types): PageData 干掉顶层 any index signature 让 build lint 过
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>
1 parent e17d2b8 commit 0221ac9

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

app/types/doc.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ export interface PageData {
3737
hidden?: boolean;
3838
docId?: string;
3939
lang?: string;
40-
[key: string]: any;
40+
[key: string]: unknown;
4141
};
42-
/**
43-
* 允许通过索引访问其他动态属性
44-
*/
45-
[key: string]: any;
42+
// 故意不挂顶层 [key: string]: unknown 索引签名 —— Fumadocs 的 page.data 由
43+
// zod DocOut 推出,没有 index signature;如果在 PageData 上挂一个,as PageData
44+
// 会触发 TS2352 "neither type sufficiently overlaps"。所有需要的字段都已
45+
// 在上面显式声明;真要拓展加新字段,往这里加显式 ? 字段,别走 escape hatch。
4646
}

0 commit comments

Comments
 (0)