Skip to content

Commit cdf9948

Browse files
committed
fix(ts): 修复 typecheck 两处报错
1. leaderboard as Row[] → leaderboard as unknown as Row[] JSON 字面量的 dailyCounts 各自是不同 literal 类型,和 Row 的 Record<string, number> 索引签名不兼容,CI tsc --noEmit 报 TS2352。先经 unknown 绕开。 2. ProfileCard title prop 必填 string,但 UserPaperItem 引入 itemKey 后 title 变可选。 兜底为 p.title || p.itemKey || "(untitled paper)"。
1 parent 17ee41d commit cdf9948

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

app/u/[username]/page.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,9 @@ function findContributions(githubId: number | null | undefined) {
140140
contributedDocs?: Array<{ id: string; title: string; url: string }>;
141141
dailyCounts?: Record<string, number>;
142142
};
143-
const rows = leaderboard as Row[];
143+
// 先经 unknown 再转 Row[]:JSON 的字面量类型(每条 dailyCounts 都是独立的 literal)和 Row 的
144+
// Record<string, number> 索引签名不兼容,tsc --noEmit 会报 TS2352。先走 unknown 绕开。
145+
const rows = leaderboard as unknown as Row[];
144146
const idStr = String(githubId);
145147
const match = rows.find((r) => r.id === idStr);
146148
if (!match) return { docs: [], points: 0, commits: 0, dailyCounts: {} };
@@ -315,7 +317,8 @@ export default async function UserProfilePage({ params }: Param) {
315317
key={`paper-${idx}`}
316318
kind="PAPER"
317319
index={idx + 1}
318-
title={p.title}
320+
// title 在 UserPaperItem 里允许 itemKey-only(title 可能缺),这里兜底
321+
title={p.title || p.itemKey || "(untitled paper)"}
319322
meta={[p.authors, p.year].filter(Boolean).join(", ")}
320323
summary={p.abstract}
321324
detail={p.abstract}

0 commit comments

Comments
 (0)